chid 0.1.6 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +27 -0
  5. data/CONTRIBUTING.md +78 -0
  6. data/Gemfile.lock +34 -34
  7. data/README.md +135 -89
  8. data/bin/chid +2 -25
  9. data/chid.gemspec +0 -6
  10. data/lib/chid.rb +0 -66
  11. data/lib/chid/chid_config.rb +6 -83
  12. data/lib/chid/command.rb +1 -1
  13. data/lib/chid/commands/alias/create.rb +53 -0
  14. data/lib/chid/commands/config.rb +48 -0
  15. data/lib/chid/commands/currency/convert.rb +50 -0
  16. data/lib/chid/commands/currency/list.rb +34 -0
  17. data/lib/chid/commands/currency/now.rb +47 -0
  18. data/lib/chid/commands/gitflow/commit.rb +0 -1
  19. data/lib/chid/commands/github.rb +40 -0
  20. data/lib/chid/commands/init.rb +1 -2
  21. data/lib/chid/commands/install.rb +1 -0
  22. data/lib/chid/commands/installs/dotfile.rb +27 -11
  23. data/lib/chid/commands/installs/node.rb +5 -3
  24. data/lib/chid/commands/installs/postgres.rb +6 -3
  25. data/lib/chid/commands/installs/rvm.rb +9 -4
  26. data/lib/chid/commands/installs/vim.rb +69 -0
  27. data/lib/chid/commands/pr.rb +63 -0
  28. data/lib/chid/commands/tmux/open.rb +3 -2
  29. data/lib/chid/commands/workstation/create.rb +101 -0
  30. data/lib/chid/commands/workstation/destroy.rb +61 -0
  31. data/lib/chid/commands/workstation/open.rb +4 -4
  32. data/lib/chid/github_api.rb +9 -0
  33. data/lib/chid/version.rb +1 -1
  34. data/spec/lib/chid/commands/alias/create_spec.rb +55 -0
  35. data/spec/lib/chid/commands/init_spec.rb +4 -2
  36. data/spec/lib/chid/commands/pr_spec.rb +68 -0
  37. data/spec/lib/chid/commands/workstation/create_spec.rb +153 -0
  38. data/spec/support/.bashrc +7 -0
  39. data/spec/support/.chid.config +7 -0
  40. data/tasks/install/yadr_dotfiles.rake +1 -0
  41. data/tasks/run/postgres.rake +1 -0
  42. data/tasks/update/os.rake +1 -0
  43. metadata +21 -58
  44. data/#README.md# +0 -221
  45. data/Rakefile +0 -18
  46. data/lib/chid/yandex_translate_api.rb +0 -39
  47. data/tasks/chid/config.rake +0 -5
  48. data/tasks/chid/init.rake +0 -19
  49. data/tasks/chid/install.rake +0 -14
  50. data/tasks/chid/start.rake +0 -26
  51. data/tasks/chid/update.rake +0 -14
  52. data/tasks/currency/convert.rake +0 -9
  53. data/tasks/currency/current.rake +0 -11
  54. data/tasks/currency/list.rake +0 -10
  55. data/tasks/github.rake +0 -12
  56. data/tasks/help.rake +0 -178
  57. data/tasks/install/node.rake +0 -18
  58. data/tasks/install/postgres.rake +0 -18
  59. data/tasks/install/rvm.rake +0 -21
  60. data/tasks/news.rake +0 -11
  61. data/tasks/stack_overflow.rake +0 -20
  62. data/tasks/tmux/config_windows.rake +0 -8
  63. data/tasks/tmux/new_session.rake +0 -9
  64. data/tasks/translate/yandex_list.rake +0 -7
  65. data/tasks/translate/yandex_translate.rake +0 -8
  66. data/tasks/workstation/create.rake +0 -23
  67. data/tasks/workstation/destroy.rake +0 -14
  68. data/tasks/workstation/list.rake +0 -10
  69. data/tasks/workstation/open.rake +0 -29
data/bin/chid CHANGED
@@ -1,30 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'chid'
4
- require 'rake'
5
4
 
6
- task = ARGV.join(" ")
5
+ task = ARGV || ['-h']
7
6
 
8
- #puts "TASK: #{ARGV}"
9
-
10
- if task.empty?
11
- #Rake.application.run
12
- Chid::start
13
- else
14
- Chid::Command.run(ARGV)
15
- #if task == 'install node'
16
- # Chid::Commands::Installs::Node.new().run
17
- #elsif task == 'install postgres'
18
- # Chid::Commands::Installs::Postgres.new().run
19
- #elsif task == 'install rvm'
20
- # Chid::Commands::Installs::Rvm.new().run
21
- #elsif task == 'install dotfile'
22
- # Chid::Commands::Installs::Dotfile.new().run
23
- #elsif task == 'install'
24
- # Chid::Commands::Install.new(Chid::chid_config_path).run
25
- #else
26
- # puts "Invalid task name. Try again"
27
- #end
28
- end
29
-
30
- #Rake.application[task].invoke
7
+ Chid::Command.run(task)
@@ -15,19 +15,13 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib", "tasks"]
20
19
 
21
20
  spec.add_development_dependency 'pry'
22
21
  spec.add_development_dependency 'rspec'
23
22
 
24
- # Tasks runner
25
- spec.add_dependency 'rake'
26
23
  # Simple HTTP request
27
24
  spec.add_runtime_dependency 'http'
28
25
  # Prompt utils
29
26
  spec.add_dependency 'tty-prompt'
30
- # Google translate
31
- spec.add_dependency 'easy_translate'
32
-
33
27
  end
@@ -1,8 +1,6 @@
1
- require 'rake'
2
1
  require 'yaml'
3
2
  require 'tty-prompt'
4
3
  require 'http'
5
- require 'easy_translate'
6
4
 
7
5
  require 'chid/command'
8
6
 
@@ -11,71 +9,7 @@ dir = File.join(File.dirname(__FILE__))
11
9
  glob = Dir.glob(dir + "/chid/**/*.rb")
12
10
  glob.each { |r| require r }
13
11
 
14
- dir_tasks = File.expand_path('..', File.dirname(__FILE__))
15
- dir = File.join(dir_tasks, 'tasks')
16
- glob = Dir.glob(dir + "/**/*.rake")
17
- glob.each { |r| load r }
18
-
19
12
  module Chid
20
-
21
- def self.chid_config
22
- @chid_config ||= ChidConfig.new
23
- end
24
-
25
- def self.start
26
- prompt = TTY::Prompt.new(help_color: :green)
27
- confirm_install = -> (action, &block) {
28
- matched = /^install:(.*)/.match(action)
29
- return block.() unless matched
30
-
31
- action_name = matched.captures.first
32
- if prompt.yes?("Can I install the #{action_name}?")
33
- block.()
34
- else
35
- puts "\nNo problem. What do you need?"
36
- end
37
- }
38
-
39
- Main.new(chid_config).init do |action, args|
40
- rake_task = Rake::Task[action]
41
- task_args = Rake::TaskArguments.new(rake_task.arg_names, args)
42
-
43
- confirm_install.(action) do
44
- rake_task.execute(task_args)
45
- end
46
-
47
- puts "\nDone! What else?"
48
- end
49
- end
50
-
51
- def self.chid_config_path
52
- home_path = File.expand_path("~/")
53
- chid_config_path = File.join(home_path, '.chid.config')
54
- chid_config_path
55
- end
56
-
57
- def self.username
58
- on_linux { return %x[echo $USER].strip }
59
- on_osx { return %x[echo $(logname)].strip }
60
- end
61
-
62
- def self.on_linux
63
- if platform =~ /Linux/
64
- yield
65
- end
66
- end
67
-
68
- def self.on_osx
69
- if platform =~ /Darwin/
70
- yield
71
- end
72
- end
73
-
74
- def self.platform
75
- %x{echo $(uname -s)}.strip
76
- end
77
-
78
-
79
13
  # The Regex Actions are used to execute automatically some Rake::Task
80
14
  #
81
15
  # The Keys are the name of the task
@@ -2,55 +2,33 @@ class ChidConfig
2
2
 
3
3
  attr_reader :chid_path, :home_path, :chid_config_path
4
4
 
5
- def initialize
5
+ def initialize(home_base_path: "~/")
6
6
  @chid_path = Dir.pwd
7
- @home_path = File.expand_path("~/")
7
+ @home_path = File.expand_path(home_base_path)
8
8
  @chid_config_path = File.join(home_path, '.chid.config')
9
9
  end
10
10
 
11
- def configure
12
- print "\nConfigurating the Chid app...\n"
13
-
14
- create_chid_alias_on_bashrc
15
- create_an_empty_chid_config_file
16
-
17
- print "\nConfiguration done!\n"
18
- end
19
-
20
- def configure_chid_file_only
21
- print "\nConfigurating the Chid app...\n"
22
-
23
- create_an_empty_chid_config_file
24
-
25
- print "\nConfiguration done!\n"
26
- end
27
-
28
- def username
11
+ def self.username
29
12
  on_linux { return %x[echo $USER].strip }
30
13
  on_osx { return %x[echo $(logname)].strip }
31
14
  end
32
15
 
33
- def on_linux
16
+ def self.on_linux
34
17
  if platform =~ /Linux/
35
18
  yield
36
19
  end
37
20
  end
38
21
 
39
- def on_osx
22
+ def self.on_osx
40
23
  if platform =~ /Darwin/
41
24
  yield
42
25
  end
43
26
  end
44
27
 
45
- def platform
28
+ def self.platform
46
29
  %x{echo $(uname -s)}.strip
47
30
  end
48
31
 
49
- def chid_rake_path
50
- data = YAML.load_file chid_config_path
51
- data[:chid][:chid_path]
52
- end
53
-
54
32
  def all_workstations
55
33
  data = YAML.load_file chid_config_path
56
34
  data[:chid][:workstations]
@@ -82,59 +60,4 @@ class ChidConfig
82
60
  YAML.dump(data, file)
83
61
  end
84
62
  end
85
-
86
- private
87
- def create_chid_alias_on_bashrc
88
- config_path = zshrc_file_exist? ? zshrc_path : bashrc_path
89
- print "\nCreating the chid alias on your "
90
- print "#{config_path}\n".blue
91
-
92
- File.open(config_path, 'a') do |file|
93
- file.write "\nalias chid='rake -f #{chid_path}/Rakefile'" unless chid_config_file_exist?
94
- end
95
- print "\nTo reload your "
96
- print "profile ".green
97
- print "should run: "
98
- print "source #{config_path}\n".blue
99
- end
100
-
101
- def zshrc_file_exist?
102
- File.exist?(zshrc_path)
103
- end
104
-
105
- def zshrc_path
106
- File.join(home_path, '.zshrc')
107
- end
108
-
109
- def bashrc_path
110
- File.join(home_path, '.bashrc')
111
- end
112
-
113
- def chid_config_file_exist?
114
- File.exist?(chid_config_path)
115
- end
116
-
117
- def create_an_empty_chid_config_file
118
- print "\nCreating or Updating the "
119
- print "~/.chid.config ".blue
120
- print "file\n"
121
-
122
- base_config = {
123
- chid: {
124
- chid_path: chid_path,
125
- workstations: {}
126
- }
127
- }
128
- if chid_config_file_exist?
129
- data = YAML.load_file chid_config_path
130
- data[:chid][:chid_path] = data[:chid].fetch(:chid_path, chid_path)
131
- data[:chid][:workstations] = data[:chid].fetch(:workstations, {})
132
- base_config = data
133
- end
134
-
135
- File.open(chid_config_path, 'w') do |file|
136
- YAML.dump(base_config, file)
137
- end
138
- end
139
-
140
63
  end
@@ -70,7 +70,7 @@ Commands:
70
70
  private
71
71
 
72
72
  def arg_is_an_option?(arg)
73
- arg.include?('-')
73
+ arg.start_with?('-')
74
74
  end
75
75
 
76
76
  def options_with_values(options, arg)
@@ -0,0 +1,53 @@
1
+ module Chid
2
+ module Commands
3
+ module Alias
4
+ class Create < Command
5
+
6
+ command :'alias create'
7
+
8
+ self.summary = 'Create a new alias'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid alias create -command {COMMAND} -alias {ALIAS}
14
+
15
+ Example:
16
+
17
+ $ chid alias create -command "chid workstation create" -alias cwo
18
+
19
+ DESC
20
+ self.arguments = ['-command', '-alias']
21
+
22
+ def run
23
+ add_command_on_bashrc
24
+
25
+ print "Please run: source ~/.bashrc".blue
26
+ end
27
+
28
+ private
29
+
30
+ def add_command_on_bashrc
31
+ File.open(bashrc_path, 'a') { |file| file.puts shell_command }
32
+ end
33
+
34
+ def bashrc_path
35
+ @bashrc_path ||= File.join(Dir.home, '.bashrc')
36
+ end
37
+
38
+ def shell_command
39
+ "alias #{alias_value}='#{command}'"
40
+ end
41
+
42
+ def alias_value
43
+ options['-alias'].first
44
+ end
45
+
46
+ def command
47
+ options['-command'].first
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,48 @@
1
+ module Chid
2
+ module Commands
3
+ class Config < Command
4
+
5
+ command :'config'
6
+
7
+ self.summary = 'Open the .chid.config file using any source you want. By default is vim.'
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid config
13
+ or
14
+ $ chid config -editor [EDITOR_NAME]
15
+
16
+ Open the .chid.config file using any source you want. By default is vim.
17
+
18
+ Example how chid will open the config file:
19
+ $ chid config -editor vim
20
+
21
+ It will be executed:
22
+ $ vim ~/.chid.config
23
+
24
+ Options:
25
+
26
+ -editor EDITOR_NAME
27
+
28
+ DESC
29
+ self.arguments = ['-editor']
30
+
31
+ def run
32
+ puts "\nOpening the .chid.config..."
33
+ system("#{editor} #{chid_config_path}")
34
+ end
35
+
36
+ private
37
+
38
+ def editor
39
+ options['-editor']&.compact&.join || 'vim'
40
+ end
41
+
42
+ def chid_config_path
43
+ @chid_config_path ||= ::ChidConfig.new.chid_config_path
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,50 @@
1
+ module Chid
2
+ module Commands
3
+ module Currency
4
+ class Convert < Command
5
+
6
+ command :'currency convert'
7
+
8
+ self.summary = 'You can convert an amount between types. Default -to BRL, -from USD'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid currency convert -amount 10.5
14
+ or
15
+ $ chid currency convert -amount 10.5 -to BRL -from USD
16
+
17
+ You can convert an amount between types. Default -to BRL, -from USD
18
+
19
+ To see all list of Source avaialble, please run `chid currency list`
20
+
21
+ Options:
22
+
23
+ -amount AMOUNT_TO_CONVERT
24
+ -to SOURCE_TO_FINAL_VALUE
25
+ -from SOURCE_TO_BE_REFERANCE
26
+
27
+ DESC
28
+ self.arguments = ['-amount', '-to', '-from']
29
+
30
+ def run
31
+ currency = CurrencyApi.convert(amount: amount, to: to, from: from)
32
+ puts "Converted amount: #{amount} #{from} is #{currency} #{to}"
33
+ end
34
+
35
+ def amount
36
+ options['-amount']&.compact.first.to_f|| 0.0
37
+ end
38
+
39
+ def to
40
+ options['-to']&.compact&.join || 'BRL'
41
+ end
42
+
43
+ def from
44
+ options['-from']&.compact&.join || 'USD'
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ module Chid
2
+ module Commands
3
+ module Currency
4
+ class List < Command
5
+
6
+ command :'currency list'
7
+
8
+ self.summary = 'All list of available Source to use on `now` and `convert commands`'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid currency list
14
+
15
+ All list of available Source to use on `now` and `convert commands`
16
+
17
+ To get current value, please run `chid currency now`
18
+
19
+ To convert some value, please run `chid currency convert `
20
+
21
+ Options:
22
+
23
+ DESC
24
+ self.arguments = []
25
+
26
+ def run
27
+ types = CurrencyApi::SOURCES
28
+ puts "Types available:\n\n"
29
+ types.each { |k, v| puts "#{k} => #{v}"}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end