kubs_cli 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd84c7a6eff0c3353025dda91835c2e1fc2dab68cef3e26bad405d881e9842cf
4
+ data.tar.gz: fb9f3d9f84a97e2ec26252f33e623c3ef43c479528e24e77f7fb9e7b65b299ea
5
+ SHA512:
6
+ metadata.gz: 69b6d366c83e73c55c53ec984102d44d074174d7876b0aa593eede2d5fd155eb332f43668ce6c72bc0c4202f8d1ce68fcb2830dc9d22d33557cb3c1867b97aa1
7
+ data.tar.gz: f73eadae691ac82078858180a1758df2739806e846202667dcaf5d0e8df3b0d739ffee2277a7415af097a0a25ee7122fd5fd0423db56d60764e24cb5713872c1
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ tags
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.2
data/Dockerfile ADDED
@@ -0,0 +1,24 @@
1
+ FROM ruby:2.6.3
2
+
3
+ RUN apt update && apt upgrade -y
4
+
5
+ # libffi needed for libffi gem
6
+ RUN apt install -y libffi-dev apt-utils git
7
+
8
+ RUN git clone https://github.com/ParamagicDev/config-files.git $HOME/config-files
9
+
10
+ # copy the directory
11
+ RUN mkdir $HOME/myapp
12
+ WORKDIR $HOME/myapp
13
+ COPY . $HOME/myapp
14
+ RUN gem install bundler
15
+ RUN bundle install
16
+
17
+ RUN rake build && gem install pkg/*
18
+
19
+
20
+ # Create a user, and give them sudo privileges if needed
21
+ # password is 'docker'
22
+ # RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
23
+ # USER docker
24
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in kubs-cli.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kubs_cli (0.1.2)
5
+ rake (~> 10.0)
6
+ thor (~> 0.20)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ ffi (1.11.1)
14
+ formatador (0.2.5)
15
+ guard (2.15.0)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (>= 1.0.12, < 2.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.9.12)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ guard-compat (1.2.1)
25
+ guard-rspec (4.7.3)
26
+ guard (~> 2.1)
27
+ guard-compat (~> 1.1)
28
+ rspec (>= 2.99.0, < 4.0)
29
+ listen (3.1.5)
30
+ rb-fsevent (~> 0.9, >= 0.9.4)
31
+ rb-inotify (~> 0.9, >= 0.9.7)
32
+ ruby_dep (~> 1.2)
33
+ lumberjack (1.0.13)
34
+ method_source (0.9.2)
35
+ nenv (0.3.0)
36
+ notiffany (0.1.1)
37
+ nenv (~> 0.1)
38
+ shellany (~> 0.0)
39
+ pry (0.12.2)
40
+ coderay (~> 1.1.0)
41
+ method_source (~> 0.9.0)
42
+ rake (10.5.0)
43
+ rb-fsevent (0.10.3)
44
+ rb-inotify (0.10.0)
45
+ ffi (~> 1.0)
46
+ rspec (3.8.0)
47
+ rspec-core (~> 3.8.0)
48
+ rspec-expectations (~> 3.8.0)
49
+ rspec-mocks (~> 3.8.0)
50
+ rspec-core (3.8.2)
51
+ rspec-support (~> 3.8.0)
52
+ rspec-expectations (3.8.4)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-mocks (3.8.1)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-support (3.8.2)
59
+ ruby_dep (1.5.0)
60
+ shellany (0.0.1)
61
+ thor (0.20.3)
62
+ yard (0.9.20)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 2.0)
69
+ guard (~> 2.15)
70
+ guard-rspec (~> 4.0)
71
+ kubs_cli!
72
+ pry (~> 0.12.0)
73
+ rspec (~> 3.0)
74
+ yard (~> 0.9)
75
+
76
+ BUNDLED WITH
77
+ 2.0.2
data/Guardfile ADDED
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ # Note: The cmd option is now required due to the increasing number of ways
21
+ # rspec may be run, below are examples of the most common uses.
22
+ # * bundler: 'bundle exec rspec'
23
+ # * bundler binstubs: 'bin/rspec'
24
+ # * spring: 'bin/rspec' (This will use spring if running and you have
25
+ # installed the spring binstubs per the docs)
26
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
27
+ # * 'just' rspec: 'rspec'
28
+
29
+ guard :rspec, cmd: 'bundle exec rspec' do
30
+ require 'guard/rspec/dsl'
31
+ dsl = Guard::RSpec::Dsl.new(self)
32
+
33
+ # Feel free to open issues for suggestions and improvements
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+
41
+ # Ruby files
42
+ ruby = dsl.ruby
43
+ dsl.watch_spec_files_for(ruby.lib_files)
44
+
45
+ # Rails files
46
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
47
+ dsl.watch_spec_files_for(rails.app_files)
48
+ dsl.watch_spec_files_for(rails.views)
49
+
50
+ watch(rails.controllers) do |m|
51
+ [
52
+ rspec.spec.call("routing/#{m[1]}_routing"),
53
+ rspec.spec.call("controllers/#{m[1]}_controller"),
54
+ rspec.spec.call("acceptance/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
65
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
71
+ end
72
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 paramagicdev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # KubsCLI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kubs/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Prerequisites
8
+
9
+ Ruby 2.0+ (Tested with 2.6.[2-3])
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'kubs_cli'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install kubs_cli
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ gem install kubs_cli
31
+ kubs -v # version
32
+ kubs init # Creates a $HOME/.kubs directory
33
+ kubs install # Installs items as defined by $HOME/.kubs/dependencies.yaml
34
+ kubs copy # Copies from $HOME/config-files/(dotfiles|gnome-terminal-settings) to $HOME
35
+ kubs pull # Copes from $HOME/.(dotfiles) to $HOME/config-files(dotfiles|gnome-terminal-settings)
36
+ kubs git_pull
37
+ kubs git_push
38
+ ```
39
+
40
+ ### Extending
41
+
42
+ The `$HOME/.kubs` is a good directory to check out
43
+
44
+ The `$HOME/.kubs/dependencies.yaml` is structed to be extended without updating my gem
45
+
46
+ ### Messing with docker
47
+
48
+ ```bash
49
+ docker build --tag=kubs-cli .
50
+ docker run -it kubs-cli /bin/bash
51
+ ```
52
+
53
+ ## Testing
54
+
55
+ ```bash
56
+ bundle install
57
+ bundle exec rake spec
58
+
59
+ # OR
60
+
61
+ bundle exec rspec
62
+ ```
63
+
64
+ ### Testing in docker
65
+
66
+ ```bash
67
+ docker build --tag=kubs-cli .
68
+ docker run -it kubs-cli /bin/bash
69
+ bundle exec rspec
70
+
71
+ # OR
72
+
73
+ bundle exec rake spec
74
+ ```
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ParamagicDev/kubs_cli.
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'kubs_cli'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/kubs ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'kubs_cli'
5
+
6
+ KubsCLI::CLI.start(ARGV)
data/kubs_cli.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'kubs_cli/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'kubs_cli'
9
+ spec.version = KubsCLI::VERSION
10
+ spec.authors = ['paramagicdev']
11
+ spec.email = ['konnor5456@gmail.com']
12
+
13
+ spec.summary = 'Konnor\'s Ubuntu Based Setup & CLI'
14
+ spec.homepage = 'https://github.com/ParamagicDev/kubs_cli'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/ParamagicDev/kubs_cli'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/ParamagicDev/kubs_cli/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'guard', '~> 2.15'
34
+ spec.add_development_dependency 'guard-rspec', '~> 4.0'
35
+ spec.add_development_dependency 'pry', '~> 0.12.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'yard', '~> 0.9'
38
+ spec.add_runtime_dependency 'rake', '~> 10.0'
39
+ spec.add_runtime_dependency 'thor', '~> 0.20'
40
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ KubsCLI.configure do |config|
4
+ # Where you want the dotfiles to be saved
5
+ config.local_dir = Dir.home
6
+ config.dependencies = File.join(Dir.home, '.kubs', 'dependencies.yaml')
7
+
8
+ # Where you have your dotfiles / misc_files saved
9
+ config.config_files = File.join(Dir.home, 'config-files')
10
+
11
+ # Where you have you dotfiles
12
+ config.dotfiles = File.join(config.config_files, 'dotfiles')
13
+
14
+ # Gnome Terminal Settings
15
+ config.gnome_terminal_settings = File.join(config.config_files,
16
+ 'gnome_terminal_settings')
17
+ end
@@ -0,0 +1,48 @@
1
+ apt:
2
+ command: sudo apt install -y || apt install -y
3
+ packages:
4
+ # Libraries
5
+ - software-properties-common gnupg2 less ufw ack-grep libfuse2
6
+ apt-transport-https ca-certificates build-essential bison
7
+ zlib1g-dev libyaml-dev libcurl4-openssl-dev libssl-dev
8
+ libgdbm-dev libreadline-dev libffi-dev fuse make gcc libxml2-dev
9
+ re2c libbz2-dev libjpeg-turbo8-dev libpng-dev
10
+ libzip-dev libtidy-dev libxslt-dev automake libtool autoconf
11
+ flex libkrb5-dev libonig-dev
12
+
13
+ # Languages
14
+ - ruby ruby-dev golang php python3 python3-pip python-dev
15
+ python3-dev python-pip python3-neovim nodejs
16
+
17
+ # Tools
18
+ - curl tmux git vim zsh sqlite3 ctags rdoc libsqlite3-dev
19
+ openssh-client openssh-server dconf-cli gnome-terminal
20
+ postgresql pry rubygems fail2ban
21
+ neovim asciinema docker mosh yarn
22
+ silversearcher-ag virtualbox
23
+
24
+ gems:
25
+ command: gem install
26
+ packages: colorls neovim rake pry rubocop gem-ctags rails yard
27
+ thor bundler solargraph
28
+
29
+ npm_packages:
30
+ command: npm install -g
31
+ packages: neovim eslint
32
+ bash-language-server --unsafe-perm
33
+ vscode-html-languageserver-bin
34
+ vscode-css-languageserver-bin
35
+ javascript-typescript-langserv
36
+ dockerfile-language-server-nodejs
37
+
38
+ pip2_packages:
39
+ command: pip2 install --user --upgrade
40
+ packages: pynvim neovim
41
+
42
+ pip3_packages:
43
+ command: pip3 install --user --upgrade
44
+ packages: pynvim neovim
45
+
46
+ snap_packages:
47
+ command: sudo snap install
48
+ packages: heroku
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module KubsCLI
6
+ class CLI < Thor
7
+ class_option(:config, aliases: :c,
8
+ default: File.join(Dir.home, '.kubs', 'config.rb'))
9
+
10
+ desc 'version', 'prints the kubs-cli version information'
11
+ def version
12
+ puts "kubs-cli version #{KubsCLI::VERSION}"
13
+ end
14
+ map %w[-v --version] => :version
15
+
16
+ # desc 'init [-c CONFIG_DIRECTORY]', 'initializes the ~/.kubs dir'
17
+ desc 'init', 'initializes the ~/.kubs dir'
18
+ def init
19
+ puts "Adding .kubs to #{Dir.home}..."
20
+ KubsCLI.create_config_dir
21
+ end
22
+
23
+ # desc 'copy [-d DOTFILES -g GNOME_TERMINAL_SETTINGS]', 'copies from KUBS_DOTFILES/* to $HOME/*'
24
+ desc 'copy', 'copies from KUBS_DOTFILES/* to $HOME/*'
25
+ def copy
26
+ run_command { KubsCLI::Copy.new.copy_all }
27
+ end
28
+
29
+ # desc 'pull [-d DOTFILES -g GNOME_TERMINAL_SETTINGS]', 'copies to your config repo'
30
+ desc 'pull', 'copies to your config repo'
31
+ def pull
32
+ run_command { KubsCLI::Pull.new.pull_all }
33
+ end
34
+
35
+ desc 'install', 'installs from .kubs/dependencies.yaml'
36
+ def install
37
+ run_command { KubsCLI::Install.new.install_all }
38
+ end
39
+
40
+ # desc 'git push [-r CONFIG_FILES_REPO]', 'pushes your config_files upstream'
41
+ desc 'git_push', 'pushes your config_files upstream'
42
+ def git_push
43
+ message ||= 'auto push files'
44
+
45
+ swap_dir do
46
+ Rake.sh('git add -A')
47
+ Rake.sh("git commit -m \"#{message}\"")
48
+ Rake.sh('git push')
49
+ rescue RuntimeError => e
50
+ KubsCLI.add_error(e: e, msg: 'Something went wrong pushing your repo')
51
+ end
52
+ end
53
+
54
+ # desc 'git pull [-r CONFIG_FILES_REPO]', 'pulls your config_files downstream'
55
+ desc 'git_pull', 'pulls your config_files downstream'
56
+ def git_pull
57
+ swap_dir { Rake.sh('git pull') }
58
+ rescue RuntimeError => e
59
+ KubsCLI.add_error(e: e, msg: 'Ran into an error pulling down your repo')
60
+ end
61
+
62
+ desc 'git_status', 'provides the status of your config_files'
63
+ def git_status
64
+ swap_dir { Rake.sh('git status') }
65
+ end
66
+
67
+ no_commands do
68
+ def swap_dir
69
+ KubsCLI.load_configuration(options[:config])
70
+ Rake.cd(KubsCLI.configuration.config_files)
71
+ yield
72
+ end
73
+
74
+ def run_command
75
+ KubsCLI.load_configuration
76
+ yield
77
+ KubsCLI.print_errors
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubsCLI
4
+ # Used for keeping a consistent config across the entire project
5
+ class Configuration
6
+ # local files
7
+ attr_accessor :local_dir
8
+
9
+ # Dependencies to install
10
+ attr_accessor :dependencies
11
+
12
+ # remote files to be used
13
+ attr_accessor :config_files, :dotfiles, :gnome_terminal_settings
14
+
15
+ def initialize
16
+ # Values for items to be copied to
17
+ @local_dir = Dir.home
18
+
19
+ # values for items to be copied from
20
+ # set to nil so that someone must set a path
21
+ @config_files = nil
22
+ @dotfiles = nil
23
+ @gnome_terminal_settings = nil
24
+ @dependencies = nil
25
+ end
26
+ end
27
+
28
+ def self.configure
29
+ @configuration ||= Configuration.new
30
+ yield(configuration)
31
+ end
32
+
33
+ def self.configuration
34
+ @configuration ||= Configuration.new
35
+ end
36
+
37
+ def self.reset_configuration
38
+ @configuration = Configuration.new
39
+ end
40
+
41
+ def self.load_configuration(file = File.join(Dir.home, '.kubs', 'config.rb'))
42
+ msg = 'Unable to location a configuration file. The default location is'
43
+ msg += '$HOME/.kubs/config.rb'
44
+ msg += "\nTo create a standard default config, run 'kubs init'"
45
+
46
+ raise Exception, msg unless File.exist?(file)
47
+
48
+ load file
49
+ end
50
+
51
+ def self.create_config_dir(path = File.join(Dir.home, '.kubs'))
52
+ fh = FileHelper.new
53
+
54
+ puts "Creating a default configuration files @ #{path}"
55
+ fh.mkdirs(path)
56
+ fh.copy(from: EXAMPLES, to: path)
57
+ end
58
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+
5
+ module KubsCLI
6
+ # Copies from a repo to $HOME directory
7
+ class Copy
8
+ attr_accessor :config
9
+
10
+ def initialize(config = KubsCLI.configuration)
11
+ @fh = FileHelper.new
12
+ @config = config
13
+ end
14
+
15
+ def copy_all
16
+ copy_dotfiles
17
+ copy_gnome_terminal_settings
18
+ end
19
+
20
+ def copy_dotfiles
21
+ Dir.each_child(@config.dotfiles) do |file|
22
+ config_file = File.join(@config.dotfiles, file)
23
+ local_file = File.join(@config.local_dir, ".#{file}")
24
+
25
+ @fh.copy(from: config_file, to: local_file)
26
+ end
27
+ end
28
+
29
+ def copy_gnome_terminal_settings
30
+ # This is the ONLY spot for gnome terminal
31
+ gnome_path = '/org/gnome/terminal/'
32
+ gnome_file = @config.gnome_terminal_settings
33
+
34
+ unless File.exist?(gnome_file)
35
+ KubsCLI.add_error(e: KubsCLI::Error, msg: "Could not find #{gnome_file}")
36
+ return
37
+ end
38
+
39
+ dconf_load = "dconf load #{gnome_path} < #{config.misc_files}/gnome_terminal_settings"
40
+ Rake.sh(dconf_load)
41
+ rescue RuntimeError => e
42
+ KubsCLI.add_error(e: e, msg: 'Unable to copy gnome settings')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+ require 'yaml'
5
+
6
+ module KubsCLI
7
+ # Used for copying files within kubs_cli
8
+ class FileHelper
9
+ # Copies a file or directory from one spot to another
10
+ # @param from [Dir, File] Where to copy from
11
+ # @param to [Dir, File] Where to copy to
12
+ # @return void
13
+ def copy(from:, to:)
14
+ return if file_does_not_exist(from)
15
+
16
+ to_dir = File.dirname(File.expand_path(to))
17
+ Rake.mkdir_p(to_dir) unless Dir.exist?(to_dir)
18
+ return Rake.cp(from, to) unless File.directory?(from)
19
+
20
+ Rake.mkdir_p(to) unless Dir.exist?(to)
21
+ Rake.cp_r(Dir["#{from}/*"], to)
22
+ end
23
+
24
+ # Creates dirs using Rake.mkdir_p if it does not exist
25
+ # @param dirs [Array<String>] The names of the dirs to create
26
+ # @return void
27
+ def mkdirs(*dirs)
28
+ dirs.flatten.each { |dir| Rake.mkdir_p(dir) unless Dir.exist?(dir) }
29
+ end
30
+
31
+ # Loads a YAML file
32
+ # @param file [File] Yaml formatted file
33
+ # @return [Hash] Returns a hash from a yaml document
34
+ def load_yaml(file)
35
+ YAML.load_file(file)
36
+ rescue StandardError => e
37
+ KubsCLI.add_error(e: e, msg: "Unable to parse your YAML file - #{file}")
38
+ end
39
+
40
+ private
41
+
42
+ #:nodoc:
43
+ def file_does_not_exist(file)
44
+ return false if File.exist?(file)
45
+
46
+ KubsCLI.add_error(e: KubsCLI::Error, msg: "#{file} does not exist")
47
+ true
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubsCLI
4
+ # Used to install items from a YAML file
5
+ class Install
6
+ def initialize(config = KubsCLI.configuration)
7
+ @fh = FileHelper.new
8
+ @yaml_file = config.dependencies
9
+ end
10
+
11
+ # Installs dependencies from a given YAML file
12
+ # @see lib/examples/dependencies.yaml
13
+ # @return Array<String> Returns an array of strings to run via Rake to install
14
+ # various packages
15
+ def create_dependencies_ary
16
+ hash = @fh.load_yaml(@yaml_file)
17
+ hash.map do |_key, value|
18
+ command = value['command']
19
+
20
+ packages = value['packages']
21
+ packages = packages.join("\n") if packages.is_a?(Array)
22
+
23
+ "#{command} #{packages}"
24
+ end
25
+ rescue StandardError => e
26
+ KubsCLI.add_error(e: e, msg: "There was an issue with creating a dependencies array from #{@yaml_file}")
27
+ end
28
+
29
+ # Installs dependencies from a give yaml_file via Rake.sh
30
+ # @return void
31
+ def install_all
32
+ ary = create_dependencies_ary
33
+
34
+ ary.each do |command|
35
+ Rake.sh(command.to_s)
36
+ rescue StandardError => e
37
+ KubsCLI.add_error(e: e, msg: "Failed with #{command}")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubsCLI
4
+ # Used to pull items into your config-files repo
5
+ class Pull
6
+ attr_accessor :config
7
+
8
+ def initialize(config = KubsCLI.configuration)
9
+ @config = config
10
+ @fh = FileHelper.new
11
+ end
12
+
13
+ # @see #pull_dotfiles
14
+ # @see #pull_gnome_terminal_settings
15
+ def pull_all
16
+ pull_dotfiles
17
+ pull_gnome_terminal_settings
18
+ end
19
+
20
+ # Pulls dotfiles into your dotfiles inside your repo
21
+ def pull_dotfiles
22
+ # Dir.each_child(@config.local_dir) do |local|
23
+ # Dir.each_child(@config.dotfiles) do |remote|
24
+ # next if local != ".#{remote}"
25
+
26
+ # local = File.join(@config.local_dir, local)
27
+ # remote = File.join(@config.dotfiles, remote)
28
+
29
+ # @fh.copy(from: local, to: remote)
30
+ # end
31
+ # end
32
+ # walk recursively
33
+
34
+ local_files = files_only(@config.local_dir)
35
+ remote_files = files_only(@config.remote_dir)
36
+
37
+ local_files.each do |l_file|
38
+ remote_files.each do |r_file|
39
+ next if l_file != ".#{r_file}"
40
+
41
+ @fh.copy(from: local, to: remote)
42
+ end
43
+ end
44
+ end
45
+
46
+ def files_only(directory)
47
+ Dir["#{directory}/**/*"].reject { |f| File.directory?(f) }
48
+ end
49
+
50
+ # Pulls gnome_terminal_settings into your dotfiles inside your repo
51
+ def pull_gnome_terminal_settings
52
+ # This is where dconf stores gnome terminal
53
+ gnome_dconf = '/org/gnome/terminal/'
54
+
55
+ orig_remote_contents = File.read(@config.gnome_terminal_settings)
56
+
57
+ Rake.sh("dconf dumb #{gnome_dconf} > #{@config.gnome_terminal_settings}")
58
+ rescue RuntimeError => e
59
+ KubsCLI.add_error(e: e, msg: 'Ran into issues dumping gnome terminal settings')
60
+
61
+ # if dconf errors, it will erase the config file contents
62
+ # So this protects against that
63
+ File.write(@config.gnome_terminal_settings, orig_remote_contents)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubsCLI
4
+ VERSION = '0.1.2'
5
+ end
data/lib/kubs_cli.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kubs_cli/file_helper'
4
+ require 'kubs_cli/configuration'
5
+ require 'kubs_cli/version'
6
+ require 'kubs_cli/cli'
7
+ require 'kubs_cli/install'
8
+ require 'kubs_cli/copy'
9
+ require 'kubs_cli/pull'
10
+
11
+ # Top level class
12
+ module KubsCLI
13
+ # Location of default config and dependencies
14
+ EXAMPLES = File.join(File.expand_path(__dir__), 'examples')
15
+
16
+ class Error < StandardError; end
17
+ # Specifies class methods
18
+ class << self
19
+ attr_accessor :errors
20
+
21
+ # Allows users to specify various configurations based on their liking
22
+ attr_writer :configuration
23
+
24
+ # Adds an error to KubsCLI#errors
25
+ # @param e [Error] Error raised
26
+ # @param msg [String] Message to display
27
+ # return Array<Error> Implicitly reutrns the array of errors
28
+ def add_error(e:, msg: nil)
29
+ KubsCLI.errors << e.exception(msg)
30
+ end
31
+
32
+ # Prints the errors when finished running
33
+ def print_errors
34
+ KubsCLI.errors.each { |e| puts e.message }
35
+ end
36
+
37
+ # Resets errors to a blank array
38
+ def clear_errors
39
+ @errors = []
40
+ end
41
+ end
42
+
43
+ # Allows access via KubsCLI.errors
44
+ @errors ||= []
45
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kubs_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - paramagicdev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.20'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.20'
125
+ description:
126
+ email:
127
+ - konnor5456@gmail.com
128
+ executables:
129
+ - kubs
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Dockerfile
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - Guardfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - exe/kubs
146
+ - kubs_cli.gemspec
147
+ - lib/examples/config.rb
148
+ - lib/examples/dependencies.yaml
149
+ - lib/kubs_cli.rb
150
+ - lib/kubs_cli/cli.rb
151
+ - lib/kubs_cli/configuration.rb
152
+ - lib/kubs_cli/copy.rb
153
+ - lib/kubs_cli/file_helper.rb
154
+ - lib/kubs_cli/install.rb
155
+ - lib/kubs_cli/pull.rb
156
+ - lib/kubs_cli/version.rb
157
+ homepage: https://github.com/ParamagicDev/kubs_cli
158
+ licenses:
159
+ - MIT
160
+ metadata:
161
+ allowed_push_host: https://rubygems.org
162
+ homepage_uri: https://github.com/ParamagicDev/kubs_cli
163
+ source_code_uri: https://github.com/ParamagicDev/kubs_cli
164
+ changelog_uri: https://github.com/ParamagicDev/kubs_cli/CHANGELOG.md
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.0.3
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Konnor's Ubuntu Based Setup & CLI
184
+ test_files: []