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
@@ -0,0 +1,61 @@
1
+ module Chid
2
+ module Commands
3
+ module Workstation
4
+ class Destroy < Command
5
+
6
+ command :'workstation destroy'
7
+
8
+ self.summary = 'Destroy a specific workstation'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid workstation destroy
14
+
15
+ Destroy a specific workstation with the selected name.
16
+
17
+ To see all workstations you can run
18
+
19
+ $ chid workstation list
20
+
21
+ DESC
22
+ self.arguments = []
23
+
24
+ def run
25
+ result = select_workstations
26
+
27
+ if result.empty?
28
+ puts "\nYou did not select any Workstation, please try again."
29
+ return
30
+ end
31
+
32
+ chid_config.destroy_workstations(result)
33
+
34
+ puts "\nWorkstations removed!"
35
+ end
36
+
37
+ private
38
+
39
+ def get_workstation_name
40
+ puts 'tell me the name of the new workstation'
41
+ print "> "
42
+ STDIN.gets.strip
43
+ end
44
+
45
+ def chid_config
46
+ ::ChidConfig.new
47
+ end
48
+
49
+ def select_workstations
50
+ prompt = TTY::Prompt.new
51
+ workstations = chid_config.all_workstations
52
+ choices = workstations.keys.map(&:to_s)
53
+
54
+ prompt
55
+ .multi_select('Select all workstations to destroy', choices)
56
+ .map(&:to_sym)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -56,7 +56,7 @@ Options:
56
56
  end
57
57
 
58
58
  def chid_config
59
- ::Chid.chid_config
59
+ ::ChidConfig.new
60
60
  end
61
61
 
62
62
  def workstations
@@ -65,7 +65,7 @@ Options:
65
65
 
66
66
  def select_workstation
67
67
  prompt = TTY::Prompt.new
68
- choices = workstations.keys
68
+ choices = workstations.keys.map(&:to_s)
69
69
  selected_workstation = prompt.select('Choose a workstation to open', choices)
70
70
  selected_workstation
71
71
  end
@@ -74,11 +74,11 @@ Options:
74
74
  puts "\nOpening all Apps"
75
75
  apps = workstations[workstation_name.to_sym]
76
76
  apps.each do |app_name|
77
- chid_config.on_osx do
77
+ ::ChidConfig.on_osx do
78
78
  system("open -a #{app_name}")
79
79
  end
80
80
 
81
- chid_config.on_linux do
81
+ ::ChidConfig.on_linux do
82
82
  system("#{app_name} >/dev/null 2>&1 &")
83
83
  end
84
84
  end
@@ -26,6 +26,15 @@ class GitHubApi
26
26
  end
27
27
  end
28
28
 
29
+ def self.prs(by:)
30
+ owner = 'rachidcalazans'
31
+ repo_name = 'chid'
32
+ uri = URI("https://api.github.com/repos/#{owner}/#{repo_name}/pulls")
33
+ request = ::HTTP.get(uri)
34
+
35
+ JSON.parse request
36
+ end
37
+
29
38
  def self.repositories(search_expression)
30
39
  uri = URI("https://api.github.com/search/repositories?q=#{search_expression}&sort=stars&order=desc")
31
40
  request = ::HTTP.get(uri)
@@ -1,3 +1,3 @@
1
1
  module Chid
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Chid::Commands::Alias::Create, '#run' do
4
+ let(:alias_command) { ['alias', 'create'] }
5
+
6
+ before do
7
+ reset_bashrc(bashrc_path)
8
+ override_bashrc_path
9
+ invoke_run
10
+ end
11
+
12
+ let(:bashrc_path) { File.join(Dir.pwd, 'spec/support/.bashrc') }
13
+ let(:override_bashrc_path) do
14
+ allow_any_instance_of(described_class).to receive(:bashrc_path)
15
+ .and_return(bashrc_path)
16
+ end
17
+ let(:invoke_run) do
18
+ argv = alias_command
19
+ .concat(arguments)
20
+ .compact
21
+
22
+ Chid::Command.run(argv)
23
+ end
24
+
25
+ context 'when given required arguments' do
26
+ let(:arguments) { ['-command', 'chid workstation open', '-alias', 'cwo'] }
27
+
28
+ it 'add alias on .bashrc' do
29
+ last_line = last_line_at_bashrc(bashrc_path)
30
+
31
+ expect(last_line).to eql "alias cwo='chid workstation open'"
32
+ end
33
+
34
+ end
35
+
36
+ def reset_bashrc(bashrc_path)
37
+ bash_file = File.open(bashrc_path, 'w') do |file|
38
+ str = <<~STR
39
+ # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
40
+ export PATH="$PATH:$HOME/.rvm/bin"
41
+ export TIDY_KEYS_PATH=/Users/rachidcalazans/Workspaces/tidy-workspace/pem_files
42
+ export TIDYTOOLS_DIR=~/Workspaces/tidy-workspace/rails-workspace/ops_scripts/tidytools
43
+ export AWS_USERNAME=rachid
44
+ # HEY
45
+ STR
46
+ file.puts str
47
+ end
48
+ end
49
+
50
+ def last_line_at_bashrc(bashrc_path)
51
+ File
52
+ .read(bashrc_path)
53
+ .split("\n").last
54
+ end
55
+ end
@@ -36,7 +36,8 @@ describe Chid::Commands::Init do
36
36
  let(:base_configuration) do
37
37
  {
38
38
  chid: {
39
- workstations: {}
39
+ workstations: {},
40
+ tmux_templates: {}
40
41
  }
41
42
  }
42
43
  end
@@ -52,7 +53,8 @@ describe Chid::Commands::Init do
52
53
  chid: {
53
54
  workstations: {
54
55
  base: 'vim'
55
- }
56
+ },
57
+ tmux_templates: {}
56
58
  }
57
59
  }
58
60
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Chid::Commands::Pr, '#run', :github, mock: true do
4
+ let(:invoke_run) do
5
+ argv = ['pr']
6
+ argv.concat(arguments)
7
+ argv.compact!
8
+ Chid::Command.run(argv)
9
+ end
10
+
11
+ context 'when given an user as arguments' do
12
+ let(:user) { 'ricmarinovic' }
13
+ let(:arguments) { ['-user', user] }
14
+
15
+ before do |example|
16
+ allow_github_prs if example.metadata[:mock]
17
+
18
+ invoke_run
19
+ end
20
+
21
+ let(:allow_github_prs) do
22
+ response_prs = [
23
+ {
24
+ 'number' => 41,
25
+ 'title' => 'Update README',
26
+ 'state' => 'open',
27
+ 'labels' => [],
28
+ 'user' => { 'login' => 'rachidcalazans'}
29
+ },
30
+ {
31
+ 'number' => 42,
32
+ 'title' => 'A new PR arrived',
33
+ 'state' => 'open',
34
+ 'labels' => [{'name' => 'in progress'}, {'name' => 'question'}],
35
+ 'user' => { 'login' => user}
36
+ },
37
+ {
38
+ 'number' => 43,
39
+ 'title' => 'One more PR',
40
+ 'state' => 'open',
41
+ 'labels' => [{'name' => 'in progress'}],
42
+ 'user' => { 'login' => user}
43
+ }
44
+ ]
45
+ allow(GitHubApi).to receive(:prs)
46
+ .with(by: user)
47
+ .and_return(response_prs)
48
+ end
49
+
50
+ it 'lists all open pull requests' do
51
+ expected_msg = <<~STR
52
+ #42 - A new PR arrived
53
+ By #{user}
54
+ Status: open
55
+ Labels: in progress, question
56
+
57
+ ---
58
+
59
+ #43 - One more PR
60
+ By #{user}
61
+ Status: open
62
+ Labels: in progress
63
+ STR
64
+
65
+ expect(invoke_run).to eql(expected_msg)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+ # @todo
3
+ # - [OK] Fix the ChidConfig.on_x for tests
4
+ # - [OK] Reset support/.chid.config with base template from Init Command or something like that
5
+ # - [OK] Refactor test code
6
+ # - [ ] Add feature to given options and arguments with workstation_name and app_names
7
+ # - chid workstation create -name tt -app_names Safari,iTerm
8
+ # - [OK] Update test code to reuse setups and contexts
9
+ # - [OK] Add the app_names option
10
+ # - [OK] Fix Bug when the workstation_name has `-`. Eg.: -name tt-maris
11
+ # - [ ] Add description to use with new arguments
12
+ #
13
+
14
+ describe ::Chid::Commands::Workstation::Create do
15
+ describe '#run' do
16
+ before do
17
+ reset_chid_config_file
18
+
19
+ set_chid_config_instance
20
+
21
+ set_plataform
22
+
23
+ set_get_option
24
+
25
+ set_multi_select_option
26
+
27
+ invoke_run
28
+ end
29
+ let(:reset_chid_config_file) do
30
+ template_data = {
31
+ chid: {
32
+ workstations: {},
33
+ tmux_templates: {}
34
+ }
35
+ }
36
+
37
+ File.open(chid_config.chid_config_path, 'w') do |file|
38
+ YAML.dump(template_data, file)
39
+ end
40
+ end
41
+ let(:set_get_option) { allow(STDIN).to receive(:gets).and_return(workstation_name) }
42
+ let(:set_multi_select_option) { allow_any_instance_of(TTY::Prompt).to receive(:multi_select).and_return(app_names) }
43
+ let(:set_chid_config_instance) { allow(::ChidConfig).to receive(:new).and_return chid_config }
44
+ let(:set_plataform) { allow(::ChidConfig).to receive(:platform).and_return platform_name }
45
+
46
+ let(:invoke_run) do
47
+ argv = ['workstation', 'create']
48
+ argv.concat(options)
49
+ argv.compact!
50
+
51
+ Chid::Command.run(argv)
52
+ end
53
+
54
+ let(:chid_config) { ::ChidConfig.new(home_base_path: "./spec/support") }
55
+ let(:load_chid_config_as_yaml) { YAML.load_file chid_config.chid_config_path }
56
+
57
+ context 'when given a workstation name' do
58
+ let(:workstation_name) { 'tt5' }
59
+
60
+ context 'when choose an app' do
61
+ let(:app_names) { %w[Safari] }
62
+
63
+ context 'when NOT given any options' do
64
+ let(:options) { [] }
65
+
66
+ context 'when the platform is osx' do
67
+ let(:platform_name) { 'Darwin' }
68
+
69
+ it 'add the new workstation name with choosen app on .chid.config file' do
70
+ yaml_file = load_chid_config_as_yaml
71
+ result = yaml_file.dig(:chid, :workstations, :tt5)
72
+
73
+ expect(result).to eq %w[Safari]
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when given workstation name option' do
79
+ let(:options) { ['-name', workstation_name] }
80
+
81
+ context 'when the platform is osx' do
82
+ let(:platform_name) { 'Darwin' }
83
+
84
+ it 'add the new workstation name with choosen app on .chid.config file' do
85
+ yaml_file = load_chid_config_as_yaml
86
+ result = yaml_file.dig(:chid, :workstations, :tt5)
87
+
88
+ expect(result).to eq %w[Safari]
89
+ end
90
+
91
+ context 'when workstation name has `-` in the name' do
92
+ let(:workstation_name) { 'tt5-5' }
93
+ let(:set_get_option) {}
94
+
95
+ it 'add the new workstation name with choosen app on .chid.config file' do
96
+ yaml_file = load_chid_config_as_yaml
97
+ result = yaml_file.dig(:chid, :workstations, :'tt5-5')
98
+
99
+ expect(result).to eq %w[Safari]
100
+ end
101
+ end
102
+
103
+ context 'when given app_names option' do
104
+ let(:app_names) { %w[Safari iTerm] }
105
+ let(:options) { ['-name', workstation_name, '-app_names'].concat(app_names) }
106
+ let(:set_multi_select_option) do
107
+ ask_msg = 'select all apps for that workstation?'
108
+ os_app_names = ['1Password 7', 'Accelerate', 'Safari', 'iTerm']
109
+
110
+ allow_any_instance_of(::Chid::Commands::Workstation::Create).to receive(:osx_application_names).and_return [os_app_names]
111
+
112
+ allow_any_instance_of(TTY::Prompt).to receive(:multi_select)
113
+ .with(ask_msg, [os_app_names], default: [3,4])
114
+ .and_return(app_names)
115
+ end
116
+
117
+ it 'add all new options on .chid.config file' do
118
+ yaml_file = load_chid_config_as_yaml
119
+ result = yaml_file.dig(:chid, :workstations, :tt5)
120
+
121
+ expect(result).to eq %w[Safari iTerm]
122
+ end
123
+ end
124
+
125
+ context 'when given some wrong app_names option' do
126
+ let(:app_wrong_name) { 'iTerminal' }
127
+ let(:app_names) { %W[Safari #{app_wrong_name}] }
128
+ let(:options) { ['-name', workstation_name, '-app_names'].concat(app_names) }
129
+ let(:set_multi_select_option) do
130
+ ask_msg = 'select all apps for that workstation?'
131
+ os_app_names = ['1Password 7', 'Accelerate', 'Safari', 'iTerm']
132
+
133
+ allow_any_instance_of(::Chid::Commands::Workstation::Create).to receive(:osx_application_names).and_return [os_app_names]
134
+
135
+ app_correct_names = %w[Safari iTerm]
136
+ allow_any_instance_of(TTY::Prompt).to receive(:multi_select)
137
+ .with(ask_msg, [os_app_names], default: [3,4])
138
+ .and_return(app_correct_names)
139
+ end
140
+
141
+ it 'add all new options on .chid.config file with matched app_names for the wrong app_names' do
142
+ yaml_file = load_chid_config_as_yaml
143
+ result = yaml_file.dig(:chid, :workstations, :tt5)
144
+
145
+ expect(result).to eq %w[Safari iTerm]
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,7 @@
1
+ # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
2
+ export PATH="$PATH:$HOME/.rvm/bin"
3
+ export TIDY_KEYS_PATH=/Users/rachidcalazans/Workspaces/tidy-workspace/pem_files
4
+ export TIDYTOOLS_DIR=~/Workspaces/tidy-workspace/rails-workspace/ops_scripts/tidytools
5
+ export AWS_USERNAME=rachid
6
+ # HEY
7
+ alias cwo='chid workstation open'
@@ -0,0 +1,7 @@
1
+ ---
2
+ :chid:
3
+ :workstations:
4
+ :tt5:
5
+ - Safari
6
+ - iTerm
7
+ :tmux_templates: {}
@@ -1,3 +1,4 @@
1
+ # @todo: Extract it for a Command feature
1
2
  namespace :install do
2
3
 
3
4
  desc 'Install YADR Dotfiles'
@@ -1,3 +1,4 @@
1
+ # @todo: Extract it for a Command feature
1
2
  namespace :run do
2
3
 
3
4
  desc 'Start Postgres'
@@ -1,3 +1,4 @@
1
+ # @todo: Extract it for a Command feature
1
2
  namespace :update do
2
3
 
3
4
  desc 'Update os'