chid 0.1.4.pre.beta → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7a695ae60bfe3af5f460e5d2272fa495d7103a9
4
- data.tar.gz: 9bd8b66acd50421cbc5d7982f3ef15a970ada9bc
3
+ metadata.gz: 03442575a6b3ffa0fcd60f867ac6d95827c87144
4
+ data.tar.gz: c6cadbbf436b85a9e6b72a2257902414fb17e126
5
5
  SHA512:
6
- metadata.gz: 4a97cf5fc860979e4da8ed581c1d0359d944aaf46cbeafc6a1be257631b50e8609881640b8426620088176729b9d929f54012ed7ffa7f6edd62af35c40adf695
7
- data.tar.gz: 91a2a7b7797423cdd168ee901b80403bc0ab2ed41b7429f3719f553dd1d01a197345ed8217ee91527c17ff685e24c47cd9afb418c6512c8c6a753e76b30a6aee
6
+ metadata.gz: a70853be7604a95274f0f069d5f9f9a70b52a2568bd4841e45f9d052efba9ba5bbdf3ff41de94b3d9cc52860ad0e3a18a355fce7fb1e4376154ffd833f44f47e
7
+ data.tar.gz: ff2c4a51b2ea646ccce92c9c71a1619e2dbda433c3c1752ce63c7e6554031240e62e1270f0a10c03e15aa9147b00db9315b5052d4a2377a5a7e9a472123a7c69
@@ -1,7 +1,15 @@
1
- ### 0.1.3 - Beta
1
+ ### 0.1.4
2
+
3
+ * Add:
4
+ - Chid Installs Command
5
+ - Chid Workstation Command
6
+ - Chid Gitflow Command
7
+
8
+ ### 0.1.3
2
9
 
3
10
  * Add:
4
11
  - Chid Executable
12
+ - Chid Commit Command
5
13
 
6
14
  * Update:
7
15
  - Change way to show the Helper task
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chid (0.1.1)
4
+ chid (0.1.4.pre.beta)
5
5
  easy_translate
6
6
  http
7
7
  rake
@@ -10,26 +10,27 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.5.0)
13
+ addressable (2.5.1)
14
14
  public_suffix (~> 2.0, >= 2.0.2)
15
15
  coderay (1.1.1)
16
- domain_name (0.5.20170223)
16
+ diff-lcs (1.3)
17
+ domain_name (0.5.20170404)
17
18
  unf (>= 0.0.5, < 1.0.0)
18
19
  easy_translate (0.5.0)
19
20
  json
20
21
  thread
21
22
  thread_safe
22
23
  equatable (0.5.0)
23
- http (2.2.1)
24
+ http (2.2.2)
24
25
  addressable (~> 2.3)
25
26
  http-cookie (~> 1.0)
26
27
  http-form_data (~> 1.0.1)
27
28
  http_parser.rb (~> 0.6.0)
28
29
  http-cookie (1.0.3)
29
30
  domain_name (~> 0.5)
30
- http-form_data (1.0.1)
31
+ http-form_data (1.0.3)
31
32
  http_parser.rb (0.6.0)
32
- json (2.0.3)
33
+ json (2.1.0)
33
34
  method_source (0.8.2)
34
35
  necromancer (0.4.0)
35
36
  pastel (0.7.1)
@@ -41,19 +42,32 @@ GEM
41
42
  slop (~> 3.4)
42
43
  public_suffix (2.0.5)
43
44
  rake (12.0.0)
45
+ rspec (3.6.0)
46
+ rspec-core (~> 3.6.0)
47
+ rspec-expectations (~> 3.6.0)
48
+ rspec-mocks (~> 3.6.0)
49
+ rspec-core (3.6.0)
50
+ rspec-support (~> 3.6.0)
51
+ rspec-expectations (3.6.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.6.0)
54
+ rspec-mocks (3.6.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.6.0)
57
+ rspec-support (3.6.0)
44
58
  slop (3.6.0)
45
59
  thread (0.2.2)
46
60
  thread_safe (0.3.6)
47
61
  tty-color (0.4.2)
48
62
  tty-cursor (0.4.0)
49
- tty-prompt (0.11.0)
63
+ tty-prompt (0.12.0)
50
64
  necromancer (~> 0.4.0)
51
65
  pastel (~> 0.7.0)
52
66
  tty-cursor (~> 0.4.0)
53
67
  wisper (~> 1.6.1)
54
68
  unf (0.1.4)
55
69
  unf_ext
56
- unf_ext (0.0.7.2)
70
+ unf_ext (0.0.7.4)
57
71
  wisper (1.6.1)
58
72
 
59
73
  PLATFORMS
@@ -62,6 +76,7 @@ PLATFORMS
62
76
  DEPENDENCIES
63
77
  chid!
64
78
  pry
79
+ rspec
65
80
 
66
81
  BUNDLED WITH
67
- 1.14.6
82
+ 1.15.2
data/bin/chid CHANGED
@@ -5,24 +5,26 @@ require 'rake'
5
5
 
6
6
  task = ARGV.join(" ")
7
7
 
8
+ puts "TASK: #{ARGV}"
9
+
8
10
  if task.empty?
9
11
  #Rake.application.run
10
12
  Chid::start
11
13
  else
12
- puts "TASK: #{ARGV.join(" ")}"
13
- if task == 'install node'
14
- Chid::Commands::Installs::Node.new().run
15
- elsif task == 'install postgres'
16
- Chid::Commands::Installs::Postgres.new().run
17
- elsif task == 'install rvm'
18
- Chid::Commands::Installs::Rvm.new().run
19
- elsif task == 'install dotfile'
20
- Chid::Commands::Installs::Dotfile.new().run
21
- elsif task == 'install'
22
- Chid::Commands::Install.new(Chid::chid_config_path).run
23
- else
24
- puts "Invalid task name. Try again"
25
- end
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
26
28
  end
27
29
 
28
30
  #Rake.application[task].invoke
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib", "tasks"]
20
20
 
21
21
  spec.add_development_dependency 'pry'
22
+ spec.add_development_dependency 'rspec'
22
23
 
23
24
  # Tasks runner
24
25
  spec.add_dependency 'rake'
@@ -4,15 +4,11 @@ require 'tty-prompt'
4
4
  require 'http'
5
5
  require 'easy_translate'
6
6
 
7
- require 'chid/commands/install'
8
- require 'chid/commands/installs/dotfile'
9
- require 'chid/commands/installs/node'
10
- require 'chid/commands/installs/postgres'
11
- require 'chid/commands/installs/rvm'
7
+ require 'chid/command'
12
8
 
13
9
  # Require all files inside the chid folder
14
10
  dir = File.join(File.dirname(__FILE__))
15
- glob = Dir.glob(dir + "/chid/*.rb")
11
+ glob = Dir.glob(dir + "/chid/**/*.rb")
16
12
  glob.each { |r| require r }
17
13
 
18
14
  dir_tasks = File.expand_path('..', File.dirname(__FILE__))
@@ -20,61 +16,64 @@ dir = File.join(dir_tasks, 'tasks')
20
16
  glob = Dir.glob(dir + "/**/*.rake")
21
17
  glob.each { |r| load r }
22
18
 
23
-
24
19
  module Chid
25
- def self.start
26
- chid_config = ChidConfig.new
27
- prompt = TTY::Prompt.new(help_color: :green)
28
- confirm_install = -> (action, &block) {
29
- matched = /^install:(.*)/.match(action)
30
- return block.() unless matched
31
-
32
- action_name = matched.captures.first
33
- if prompt.yes?("Can I install the #{action_name}?")
34
- block.()
35
- else
36
- puts "\nNo problem. What do you need?"
37
- end
38
- }
39
20
 
40
- Main.new(chid_config).init do |action, args|
41
- rake_task = Rake::Task[action]
42
- task_args = Rake::TaskArguments.new(rake_task.arg_names, args)
21
+ def self.chid_config
22
+ @chid_config ||= ChidConfig.new
23
+ end
43
24
 
44
- confirm_install.(action) do
45
- rake_task.execute(task_args)
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?"
46
48
  end
47
-
48
- puts "\nDone! What else?"
49
49
  end
50
- end
51
50
 
52
51
  def self.chid_config_path
53
- home_path = File.expand_path("~/")
54
- chid_config_path = File.join(home_path, '.chid.config')
55
- chid_config_path
56
- end
52
+ home_path = File.expand_path("~/")
53
+ chid_config_path = File.join(home_path, '.chid.config')
54
+ chid_config_path
55
+ end
57
56
 
58
57
  def self.username
59
- on_linux { return %x[echo $USER].strip }
60
- on_osx { return %x[echo $(logname)].strip }
61
- end
58
+ on_linux { return %x[echo $USER].strip }
59
+ on_osx { return %x[echo $(logname)].strip }
60
+ end
62
61
 
63
62
  def self.on_linux
64
- if platform =~ /Linux/
65
- yield
63
+ if platform =~ /Linux/
64
+ yield
65
+ end
66
66
  end
67
- end
68
67
 
69
68
  def self.on_osx
70
- if platform =~ /Darwin/
71
- yield
69
+ if platform =~ /Darwin/
70
+ yield
71
+ end
72
72
  end
73
- end
74
73
 
75
74
  def self.platform
76
- %x{echo $(uname -s)}.strip
77
- end
75
+ %x{echo $(uname -s)}.strip
76
+ end
78
77
 
79
78
 
80
79
  # The Regex Actions are used to execute automatically some Rake::Task
@@ -0,0 +1,150 @@
1
+ module Chid
2
+ class Command
3
+
4
+ class << self
5
+
6
+ attr_accessor :summary, :description, :arguments
7
+
8
+ COMMANDS = {}
9
+
10
+ def command(cmd)
11
+ COMMANDS[cmd] = self.to_s
12
+ end
13
+
14
+ def help
15
+ if self.description.nil?
16
+ commands = String.new
17
+ COMMANDS.keys.each {|k| commands << " #{k.to_s}\n" }
18
+ self.description = <<-DESC
19
+ Usage:
20
+
21
+ $ chid [COMMAND]
22
+
23
+ To see what the Command do:
24
+
25
+ $ chid [COMMAND] -h
26
+
27
+ Commands:
28
+
29
+ #{commands}
30
+ DESC
31
+ end
32
+
33
+ puts summary
34
+ print description
35
+ end
36
+
37
+ def run(argv)
38
+ command_key = command_key(argv)
39
+ return self.help unless command_key_is_included?(command_key)
40
+ invoke(argv)
41
+ end
42
+
43
+ # Returns a mapped options with your values from @argv
44
+ #
45
+ # @param [Array<String>] argv
46
+ # The arguments passed from input.
47
+ #
48
+ # @return [Hash<String, Array>] Mapped options with your values
49
+ # The keys of hash are the options and the values of hash
50
+ # are all values for the option.
51
+ #
52
+ # @example Map an argv
53
+ # argv = ['init', '-option_1', 'value_for_option_1']
54
+ #
55
+ # map_options_with_values(argv) #=> {'-option1' => ['value_for_option_1']}
56
+ #
57
+ def map_options_with_values(argv)
58
+ return argv.reduce({}) do |options, arg|
59
+ new_options = options
60
+
61
+ if arg_is_an_option?(arg)
62
+ new_options[arg] = []
63
+ next(new_options)
64
+ end
65
+
66
+ options_with_values(new_options, arg)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def arg_is_an_option?(arg)
73
+ arg.include?('-')
74
+ end
75
+
76
+ def options_with_values(options, arg)
77
+ new_options = options
78
+ last_option = new_options.keys.last
79
+ new_options[last_option] << arg if last_option
80
+
81
+ new_options
82
+ end
83
+
84
+ def command_key_is_included?(command_key)
85
+ COMMANDS.include?(command_key)
86
+ end
87
+
88
+ # Returns the command key based on argv parameter.
89
+ # That command could be a single or compost command.
90
+ #
91
+ # @param [Array<String>] argv
92
+ # The arguments passed from input.
93
+ #
94
+ # @return [Sym] the sym of the command
95
+ #
96
+ # @example Get the command_key in an argv
97
+ # argv = ['init', '-option_1', 'value_for_option_1']
98
+ #
99
+ # command_key(argv) #=> :init
100
+ #
101
+ # argv = ['init', 'chid', '-option_1', 'value_for_option_1']
102
+ #
103
+ # command_key(argv) #=> :'init chid'
104
+ #
105
+ def command_key(argv)
106
+ argv.reduce('') { |command, arg|
107
+ break(command) if arg_is_an_option?(arg)
108
+ command << "#{arg} "
109
+ }.strip.to_sym
110
+ end
111
+
112
+ # Convenience method.
113
+ # Instantiate the command and run it with the provided arguments at once.
114
+ #
115
+ # @param [String..., Array<String>] args
116
+ # The arguments to initialize the command with
117
+ #
118
+ def invoke(argv)
119
+ options = map_options_with_values(argv)
120
+ command = new_command_instance(command_key(argv), options)
121
+ return command.run if has_no_arguments?(options) || has_valid_arguments?(command.class, options)
122
+ command.class.help
123
+ end
124
+
125
+ def new_command_instance(command_key, options)
126
+ Object.const_get(COMMANDS[command_key]).new(options)
127
+ end
128
+
129
+ def has_no_arguments?(options)
130
+ options.empty?
131
+ end
132
+
133
+ def has_valid_arguments?(command_class, options)
134
+ !(command_class.arguments & options.keys).empty?
135
+ end
136
+
137
+ end
138
+
139
+ # --- Instance methods ---
140
+
141
+ public
142
+
143
+ attr_reader :options
144
+
145
+ def initialize(options)
146
+ @options = options
147
+ end
148
+
149
+ end
150
+ end
@@ -0,0 +1,92 @@
1
+ module Chid
2
+ module Commands
3
+ module Gitflow
4
+ class Commit < Command
5
+
6
+ command :commit
7
+ self.summary = 'Create a commits in based on gitFlow pattern'
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid commit
13
+
14
+ An easy way to create commits following simple steps:
15
+
16
+ First:
17
+ Choose your commit type in this options (add,Remove, Update, Refactor, Fix)
18
+
19
+ Second:
20
+ Type your commit title, a brief description of your changes
21
+
22
+ Third:
23
+ Add your description lines, describing exactly what you did
24
+
25
+ Thats it! Your commit will be created and pushed like this sample:
26
+
27
+ feature/#123 Add specific file needed to app
28
+
29
+ - specific file have now this line
30
+ - this is the description line two
31
+
32
+ DESC
33
+
34
+ self.arguments = []
35
+
36
+ def run
37
+ commit = build_commit
38
+ system("git commit -sm \"#{commit}\"")
39
+ system("git push origin #{branch}")
40
+ end
41
+
42
+ def build_commit
43
+ @commit_lines = "\n"
44
+ commit_kind = add_commit_kind
45
+ commit_title = add_commit_title
46
+ add_commit_description
47
+ commit = "#{branch_name} #{commit_kind} #{commit_title} \n #{@commit_lines}"
48
+ end
49
+
50
+ def branch
51
+ @branch ||= %x[git rev-parse --abbrev-ref HEAD].strip
52
+ end
53
+
54
+ def branch_name
55
+ @branch_name ||= branch[/\w{1,}\/#?\d{1,}/] || branch
56
+ end
57
+
58
+ def add_commit_kind
59
+ @prompt = TTY::Prompt.new
60
+ choices = ['Add', 'Remove','Update', 'Refactor','Fix']
61
+ result = @prompt.select('Select commit type: ', choices)
62
+ end
63
+
64
+ def add_commit_title
65
+ puts 'Tell me the commit title'
66
+ print '> '
67
+ commit_title = STDIN.gets.strip
68
+ end
69
+
70
+ def add_commit_description
71
+ puts 'Tell me the commit description, one action per line'
72
+ print "> "
73
+ commit_description ="- #{STDIN.gets.strip} \n"
74
+ @commit_lines << commit_description
75
+ add_commit_description unless did_commit_finished?
76
+ end
77
+
78
+ def do_push?
79
+ answers = ['Yes','No']
80
+ result_should_push = @prompt.select('Push changes?', answers)
81
+ result_should_push == 'Yes'
82
+ end
83
+
84
+ def did_commit_finished?
85
+ answers = ['Yes','No']
86
+ result_description_finished = @prompt.select('more?', answers)
87
+ result_description_finished == 'No'
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ module Chid
2
+ module Commands
3
+ class Init < Command
4
+
5
+ command :init
6
+
7
+ self.summary = 'Generate a .chid.config file on root directory'
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid init
13
+
14
+ Creates a .chid.config file on root directory if none .chid.config file exists.
15
+
16
+ To access that file will be created in `~/.chid.config`
17
+
18
+ DESC
19
+ self.arguments = []
20
+
21
+ def run
22
+ create_or_update_chid_config_file
23
+ end
24
+
25
+ private
26
+ def chid_config_path
27
+ @chid_config_path ||= ::Chid::chid_config_path
28
+ end
29
+
30
+ def create_or_update_chid_config_file
31
+ print_informations
32
+ dump_on_chid_config_file(chid_configurations)
33
+ end
34
+
35
+ def print_informations
36
+ print "\n--- Installing chid ---\n "
37
+ print "\nCreating the " unless chid_config_file_exist?
38
+ print "\nUpdating the " if chid_config_file_exist?
39
+ print "~/.chid.config ".blue
40
+ print "file\n"
41
+ end
42
+
43
+ def dump_on_chid_config_file(configurations)
44
+ File.open(chid_config_path, 'w') do |file|
45
+ YAML.dump(configurations, file)
46
+ end
47
+ end
48
+
49
+ def chid_configurations
50
+ return base_configurations unless chid_config_file_exist?
51
+
52
+ data = YAML.load_file chid_config_path
53
+ data[:chid][:workstations] = data[:chid].fetch(:workstations, {})
54
+ data
55
+ end
56
+
57
+ def base_configurations
58
+ {
59
+ chid: {
60
+ workstations: {}
61
+ }
62
+ }
63
+ end
64
+
65
+ def chid_config_file_exist?
66
+ File.exist?(chid_config_path)
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -1,7 +1,23 @@
1
1
  module Chid
2
2
  module Commands
3
3
  module Installs
4
- class Dotfile
4
+ class Dotfile < Command
5
+
6
+ command :'install dotfile'
7
+
8
+ self.summary = 'Install the Dotfile'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid install dotfile
14
+
15
+ For Linux users will install through curl and will isntall zsh and git-core
16
+
17
+ For OSx users will install through curl
18
+
19
+ DESC
20
+ self.arguments = []
5
21
 
6
22
  def run
7
23
  puts "\nInstalling the YADR Dotfiles..."
@@ -1,7 +1,23 @@
1
1
  module Chid
2
2
  module Commands
3
3
  module Installs
4
- class Node
4
+ class Node < Command
5
+
6
+ command :'install node'
7
+
8
+ self.summary = 'Install the Node'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid install node
14
+
15
+ For Linux users will install through apt-get
16
+
17
+ For OSx users will install through brew
18
+
19
+ DESC
20
+ self.arguments = []
5
21
 
6
22
  def run
7
23
  puts "\nInstalling the Node..."
@@ -1,7 +1,25 @@
1
1
  module Chid
2
2
  module Commands
3
3
  module Installs
4
- class Postgres
4
+ class Postgres < Command
5
+
6
+ command :'install postgres'
7
+
8
+ self.summary = 'Install the Postgres'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid install postgres
14
+
15
+ For Linux users will install through apt-get
16
+
17
+ For OSx users will install through brew
18
+
19
+ DESC
20
+ self.arguments = []
21
+
22
+
5
23
 
6
24
  def run
7
25
  puts "\nInstalling the Postgres..."
@@ -1,7 +1,24 @@
1
1
  module Chid
2
2
  module Commands
3
3
  module Installs
4
- class Rvm
4
+ class Rvm < Command
5
+
6
+ command :'install rvm'
7
+
8
+ self.summary = 'Install the RVM'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid install rvm
14
+
15
+ For Linux users will install through apt-get
16
+
17
+ For OSx users will install through curl
18
+
19
+ DESC
20
+ self.arguments = []
21
+
5
22
 
6
23
  def run
7
24
  puts "\nInstalling the RVM..."
@@ -0,0 +1,27 @@
1
+ module Chid
2
+ module Commands
3
+ module Workstation
4
+ class List < Command
5
+
6
+ command :'workstation list'
7
+
8
+ self.summary = 'List all existent workstations'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid workstation list
14
+
15
+ DESC
16
+ self.arguments = []
17
+
18
+ def run
19
+ chid_config = ChidConfig.new
20
+ puts "Workstations availabbe:".blue
21
+ puts chid_config.all_workstations.keys
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,90 @@
1
+ module Chid
2
+ module Commands
3
+ module Workstation
4
+ class Open < Command
5
+
6
+ command :'workstation open'
7
+
8
+ self.summary = 'Open a specific named workstation'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid workstation open
14
+ or
15
+ $ chid workstation open -name some_workstation_name
16
+
17
+ Open all apps listed in the created workstations.
18
+
19
+ To see all workstations you can run
20
+
21
+ $ chid workstation list
22
+
23
+ If no options are specified, chid will show a list of Workstations created
24
+ to be selected.
25
+
26
+ Options:
27
+
28
+ -name workstation_name Open all applications in the 'workstation_name'
29
+ -n "base two" Open all applications in the 'base two'
30
+
31
+ DESC
32
+ self.arguments = ['-name', '-n']
33
+
34
+ def run
35
+ workstation_name = workstation_name_from_options
36
+ workstation_name = select_workstation if workstation_name.empty?
37
+
38
+ open_apps(workstation_name)
39
+ end
40
+
41
+ private
42
+
43
+ # Returns the workstation name mapped from the values of the options attribute.
44
+ # Will remove all nil values and join the array of values into String
45
+ #
46
+ # @return [String] Mapped values from options attribute
47
+ # If the options does not exist, will return empty String #=> ""
48
+ #
49
+ # @example Workstation Name
50
+ # options = {'-name' => ['base', 'two']}
51
+ #
52
+ # workstation_name #=> 'base two'
53
+ #
54
+ def workstation_name_from_options
55
+ @workstation_name ||= self.class.arguments.map { |a| options[a] }.compact.join(' ')
56
+ end
57
+
58
+ def chid_config
59
+ ::Chid.chid_config
60
+ end
61
+
62
+ def workstations
63
+ @workstations ||= chid_config.all_workstations
64
+ end
65
+
66
+ def select_workstation
67
+ prompt = TTY::Prompt.new
68
+ choices = workstations.keys
69
+ selected_workstation = prompt.select('Choose a workstation to open', choices)
70
+ selected_workstation
71
+ end
72
+
73
+ def open_apps(workstation_name)
74
+ puts "\nOpening all Apps"
75
+ apps = workstations[workstation_name.to_sym]
76
+ apps.each do |app_name|
77
+ chid_config.on_osx do
78
+ system("open -a #{app_name}")
79
+ end
80
+
81
+ chid_config.on_linux do
82
+ system("#{app_name} >/dev/null 2>&1 &")
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Chid
2
- VERSION = "0.1.4-beta"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chid::Command do
4
+
5
+ let(:subject_class) { Chid::Command }
6
+
7
+ describe '.run' do
8
+
9
+ context 'When no pass any command' do
10
+ let(:argv) { options }
11
+
12
+ let(:setup_allows) { allow(subject_class).to receive(:help) }
13
+
14
+ before do
15
+ setup_allows
16
+ Chid::Command.run(argv)
17
+ end
18
+
19
+ context 'When pass :helper option' do
20
+ let(:options) { ['-h'] }
21
+
22
+ it 'Should call :help method' do
23
+ expect(subject_class).to have_received(:help)
24
+ end
25
+ end
26
+
27
+ context 'When pass invalid option' do
28
+ let(:options) { ['-invalid_option'] }
29
+
30
+ it 'Should call :help method' do
31
+ expect(subject_class).to have_received(:help)
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ context 'When pass an invalid command' do
38
+ let(:command) { 'invalid_command' }
39
+ let(:options) { [] }
40
+ let(:argv) { [command].concat(options) }
41
+
42
+ let(:setup_allows) { allow(subject_class).to receive(:help) }
43
+
44
+ before do
45
+ setup_allows
46
+ Chid::Command.run(argv)
47
+ end
48
+
49
+ it 'Should call :help method' do
50
+ expect(subject_class).to have_received(:help)
51
+ end
52
+ end
53
+
54
+ context 'When pass a valid command' do
55
+ let(:init_command_class) { double arguments: [] }
56
+ let(:init_command) { double class: init_command_class }
57
+
58
+ let(:command) { ['init'] }
59
+ let(:options) { [] }
60
+ let(:argv) { command.concat(options) }
61
+
62
+ let(:default_allows) do
63
+ allow(subject_class).to receive(:command_key_is_included?).and_return(true)
64
+ allow(subject_class).to receive(:new_command_instance).and_return(init_command)
65
+ end
66
+
67
+ let(:setup_allows) { allow(init_command_class).to receive(:help) }
68
+
69
+ before do
70
+ default_allows
71
+ setup_allows
72
+ Chid::Command.run(argv)
73
+ end
74
+
75
+ context 'When is a single command' do
76
+
77
+ let(:setup_allows) { allow(init_command).to receive(:run) }
78
+
79
+ it 'Command key should be :init' do
80
+ expect(subject_class).to have_received(:command_key_is_included?).with(:init)
81
+ end
82
+ end
83
+
84
+ context 'When is a compost command' do
85
+ let(:command) { ['init', 'chid'] }
86
+
87
+ let(:setup_allows) { allow(init_command).to receive(:run) }
88
+
89
+ it 'Command key should be :"init chid"' do
90
+ expect(subject_class).to have_received(:command_key_is_included?).with(:'init chid')
91
+ end
92
+ end
93
+
94
+ # @TODO: Extract that context to shared examples
95
+ context 'When pass :help options' do
96
+ let(:options) { ['-h'] }
97
+
98
+ it 'Command should call :help method' do
99
+ expect(init_command_class).to have_received(:help)
100
+ end
101
+ end
102
+
103
+ context 'When pass invalid options' do
104
+ let(:options) { ['-ah', 'some', 'value'] }
105
+
106
+ it 'Should call :help method' do
107
+ expect(init_command_class).to have_received(:help)
108
+ end
109
+ end
110
+
111
+ context 'When pass valid options' do
112
+ let(:options) { ['-some_valid_option', 'some', 'value'] }
113
+
114
+ let(:setup_allows) do
115
+ allow(init_command).to receive(:run)
116
+ allow(subject_class).to receive(:has_valid_arguments?).and_return(true)
117
+ end
118
+
119
+ it 'Command should call :new method with :options' do
120
+ expected_options = {
121
+ '-some_valid_option' => ['some', 'value']
122
+ }
123
+ expect(subject_class).to have_received(:new_command_instance).with(:init, expected_options)
124
+ end
125
+
126
+ it 'Command should call :run method' do
127
+ expect(init_command).to have_received(:run)
128
+ end
129
+
130
+ end
131
+
132
+ context 'When no pass any options' do
133
+ let(:options) { [] }
134
+
135
+ let(:setup_allows) do
136
+ allow(init_command).to receive(:run)
137
+ allow(subject_class).to receive(:has_valid_arguments?).and_return(false)
138
+ end
139
+
140
+ it 'Command should call :new method with :options' do
141
+ expected_options = {}
142
+ expect(subject_class).to have_received(:new_command_instance).with(:init, expected_options)
143
+ end
144
+
145
+ it 'Command should call :run method' do
146
+ expect(init_command).to have_received(:run)
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chid::Commands::Init do
4
+
5
+ let(:argv) { {} }
6
+ subject { Chid::Commands::Init.new(argv) }
7
+
8
+ # @TODO: Extract for a shared context test
9
+ describe 'Documentations classes attributes' do
10
+ it('summary should not be nil') { expect(subject.class.summary).not_to be_nil }
11
+ it('description should not be nil') { expect(subject.class.description).not_to be_nil }
12
+ it('arguments should be empty') { expect(subject.class.arguments).to be_empty }
13
+ end
14
+
15
+ describe '#run' do
16
+ let(:chid_config_path) { File.join(File.dirname(__FILE__), '.chid.config') }
17
+ let(:file_content_configurations) { YAML.load_file(chid_config_path) }
18
+
19
+ let(:default_allows) do
20
+ allow(subject).to receive(:chid_config_path).and_return(chid_config_path)
21
+ end
22
+
23
+ let(:setup) {}
24
+
25
+ before do
26
+ default_allows
27
+ setup
28
+ subject.run
29
+ end
30
+
31
+ after do
32
+ File.delete(chid_config_path) if File.exist?(chid_config_path)
33
+ end
34
+
35
+ context 'When does not exist .chid.config file' do
36
+ let(:base_configuration) do
37
+ {
38
+ chid: {
39
+ workstations: {}
40
+ }
41
+ }
42
+ end
43
+
44
+ it 'Should contains the base configuration' do
45
+ expect(file_content_configurations).to eq base_configuration
46
+ end
47
+ end
48
+
49
+ context 'When does exist .chid.config file with some configuration' do
50
+ let(:existent_configurations) do
51
+ {
52
+ chid: {
53
+ workstations: {
54
+ base: 'vim'
55
+ }
56
+ }
57
+ }
58
+ end
59
+
60
+ let(:setup) do
61
+ File.open(chid_config_path, 'w') do |file|
62
+ YAML.dump(existent_configurations, file)
63
+ end
64
+ end
65
+
66
+ it 'Should remains the existent configuration' do
67
+ expect(file_content_configurations).to eq existent_configurations
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chid::Commands::Workstation::Open, tt:true do
4
+
5
+ subject { Chid::Commands::Workstation::Open.new(options) }
6
+
7
+ describe '#run' do
8
+ let(:options) { {} }
9
+ let(:setup) { }
10
+
11
+ before do
12
+ allow(subject).to receive(:open_apps)
13
+
14
+ setup
15
+ subject.run
16
+ end
17
+
18
+ context 'when no pass any argument' do
19
+ let(:expected_workstation_name) { 'none' }
20
+
21
+ let(:setup) do
22
+ allow(subject).to receive(:select_workstation).and_return expected_workstation_name
23
+ end
24
+
25
+ it 'should call :select_workstation method' do
26
+ expect(subject).to have_received(:select_workstation).once
27
+ end
28
+
29
+ it 'should call :open_apps method' do
30
+ expect(subject).to have_received(:open_apps).with(expected_workstation_name).once
31
+ end
32
+
33
+ end
34
+
35
+ context 'when pass -name as argument' do
36
+ let(:options) { {'-name' => ['base', 'two']} }
37
+ let(:expected_workstation_name) { 'base two' }
38
+
39
+ let(:setup) do
40
+
41
+ end
42
+
43
+ it 'should call :open_apps method' do
44
+ expect(subject).to have_received(:open_apps).with(expected_workstation_name).once
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ require 'chid'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ end
@@ -1,21 +1,8 @@
1
1
  desc 'Configure default windows for development'
2
- task :tmux_config, [:name] do |t, args|
3
- name = args.fetch(:name, 'development')
4
- if name == 'development'
5
- system("tmux rename-window bash")
6
- system("tmux new-window -n app")
7
- system("tmux new-window -n server")
8
- elsif name == 'stant-api'
9
- system("tmux rename-window app")
10
- system("tmux new-window -n tests")
11
- system("tmux new-window -n server")
12
- system("tmux new-window -n bash")
13
- elsif name == 'stant-traceability'
14
- system("tmux rename-window ios-traceability")
15
- system("tmux new-window -n ios-infrastructure")
16
- system("tmux new-window -n ios-core")
17
- system("tmux new-window -n bash")
18
- end
2
+ task :tmux_config do
3
+ system("tmux rename-window bash")
4
+ system("tmux new-window -n app")
5
+ system("tmux new-window -n server")
19
6
  end
20
7
 
21
8
 
@@ -1,9 +1,8 @@
1
1
  desc 'Open or Create the new session for development key'
2
- task :tmux, [:name] do |t, args|
3
- name = args.fetch(:name, 'development')
4
- session = system("tmux attach -t #{name}")
2
+ task :tmux do
3
+ session = system('tmux attach -t development')
5
4
  unless session
6
- system("tmux new -s #{name}")
5
+ system('tmux new -s development')
7
6
  end
8
7
  end
9
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.pre.beta
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rachid Calazans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,11 +114,16 @@ files:
100
114
  - etc/img/stack.png
101
115
  - lib/chid.rb
102
116
  - lib/chid/chid_config.rb
117
+ - lib/chid/command.rb
118
+ - lib/chid/commands/gitflow/commit.rb
119
+ - lib/chid/commands/init.rb
103
120
  - lib/chid/commands/install.rb
104
121
  - lib/chid/commands/installs/dotfile.rb
105
122
  - lib/chid/commands/installs/node.rb
106
123
  - lib/chid/commands/installs/postgres.rb
107
124
  - lib/chid/commands/installs/rvm.rb
125
+ - lib/chid/commands/workstation/list.rb
126
+ - lib/chid/commands/workstation/open.rb
108
127
  - lib/chid/currency_api.rb
109
128
  - lib/chid/github_api.rb
110
129
  - lib/chid/main.rb
@@ -113,6 +132,10 @@ files:
113
132
  - lib/chid/stack_overflow_api.rb
114
133
  - lib/chid/version.rb
115
134
  - lib/chid/yandex_translate_api.rb
135
+ - spec/lib/chid/command_spec.rb
136
+ - spec/lib/chid/commands/init_spec.rb
137
+ - spec/lib/chid/commands/workstation/open_spec.rb
138
+ - spec/spec_helper.rb
116
139
  - tasks/chid/config.rake
117
140
  - tasks/chid/init.rake
118
141
  - tasks/chid/install.rake
@@ -155,9 +178,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
178
  version: '0'
156
179
  required_rubygems_version: !ruby/object:Gem::Requirement
157
180
  requirements:
158
- - - ">"
181
+ - - ">="
159
182
  - !ruby/object:Gem::Version
160
- version: 1.3.1
183
+ version: '0'
161
184
  requirements: []
162
185
  rubyforge_project:
163
186
  rubygems_version: 2.6.6