chid 0.1.6.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/CONTRIBUTING.md +75 -1
  4. data/Gemfile.lock +23 -36
  5. data/README.md +129 -79
  6. data/bin/chid +2 -25
  7. data/chid.gemspec +0 -6
  8. data/lib/chid.rb +0 -66
  9. data/lib/chid/chid_config.rb +4 -81
  10. data/lib/chid/commands/config.rb +48 -0
  11. data/lib/chid/commands/currency/convert.rb +50 -0
  12. data/lib/chid/commands/currency/list.rb +34 -0
  13. data/lib/chid/commands/currency/now.rb +47 -0
  14. data/lib/chid/commands/gitflow/commit.rb +0 -1
  15. data/lib/chid/commands/github.rb +40 -0
  16. data/lib/chid/commands/init.rb +1 -2
  17. data/lib/chid/commands/install.rb +1 -0
  18. data/lib/chid/commands/installs/dotfile.rb +1 -1
  19. data/lib/chid/commands/installs/node.rb +2 -2
  20. data/lib/chid/commands/installs/postgres.rb +2 -2
  21. data/lib/chid/commands/installs/rvm.rb +2 -2
  22. data/lib/chid/commands/installs/vim.rb +2 -2
  23. data/lib/chid/version.rb +1 -1
  24. data/spec/lib/chid/commands/init_spec.rb +4 -2
  25. data/tasks/install/yadr_dotfiles.rake +1 -0
  26. data/tasks/run/postgres.rake +1 -0
  27. data/tasks/update/os.rake +1 -0
  28. metadata +7 -52
  29. data/#README.md# +0 -222
  30. data/Rakefile +0 -18
  31. data/lib/chid/yandex_translate_api.rb +0 -39
  32. data/tasks/chid/config.rake +0 -5
  33. data/tasks/chid/init.rake +0 -19
  34. data/tasks/chid/install.rake +0 -14
  35. data/tasks/chid/start.rake +0 -26
  36. data/tasks/chid/update.rake +0 -14
  37. data/tasks/currency/convert.rake +0 -9
  38. data/tasks/currency/current.rake +0 -11
  39. data/tasks/currency/list.rake +0 -10
  40. data/tasks/github.rake +0 -12
  41. data/tasks/help.rake +0 -178
  42. data/tasks/install/node.rake +0 -18
  43. data/tasks/install/postgres.rake +0 -18
  44. data/tasks/install/rvm.rake +0 -21
  45. data/tasks/news.rake +0 -11
  46. data/tasks/stack_overflow.rake +0 -20
  47. data/tasks/tmux/config_windows.rake +0 -8
  48. data/tasks/tmux/new_session.rake +0 -9
  49. data/tasks/translate/yandex_list.rake +0 -7
  50. data/tasks/translate/yandex_translate.rake +0 -8
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
@@ -8,49 +8,27 @@ class ChidConfig
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
@@ -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
@@ -0,0 +1,47 @@
1
+ module Chid
2
+ module Commands
3
+ module Currency
4
+ class Current < Command
5
+
6
+ command :'currency now'
7
+
8
+ self.summary = 'Get the now converstion. Default -from USD -to BRL'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid currency now
14
+ or
15
+ $ chid currency now -to BRL -from USB
16
+
17
+ Get the now converstion. Default -from USD -to BRL
18
+
19
+ But you can given the options for any other Sources
20
+
21
+ To see all list of Source avaialble, please run `chid currency list`
22
+
23
+ Options:
24
+
25
+ -to SOURCE_TO_FINAL_VALUE
26
+ -from SOURCE_TO_BE_REFERANCE
27
+
28
+ DESC
29
+ self.arguments = ['-to', '-from']
30
+
31
+ def run
32
+ currency = CurrencyApi.convert(to: to, from: from)
33
+ puts "1 #{from} is #{currency} #{to}"
34
+ end
35
+
36
+ def to
37
+ options['-to']&.compact&.join || 'BRL'
38
+ end
39
+
40
+ def from
41
+ options['-from']&.compact&.join || 'USD'
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -57,7 +57,6 @@ Options:
57
57
  options_titles = {
58
58
  '-A' => 'Add',
59
59
  '-R' => 'Remove',
60
- '-U' => 'Update',
61
60
  '-Ref' => 'Refactor',
62
61
  '-F' => 'Fix'
63
62
  }
@@ -0,0 +1,40 @@
1
+ module Chid
2
+ module Commands
3
+ class Github < Command
4
+
5
+ command :'github'
6
+
7
+ self.summary = 'List all repositories from GitHub for a given SEARCH'
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid github -name rachidcalazans/chid
13
+ or
14
+ $ chid github -n rachidcalazans/chid
15
+
16
+ List all repositories from GitHub for a given SEARCH
17
+
18
+ Options:
19
+
20
+ -n NAME_TO_SEARCH
21
+ -name NAME_TO_SEARCH
22
+
23
+ DESC
24
+ self.arguments = ['-name', '-n']
25
+
26
+ def run
27
+ search_expression = name
28
+ repositories = GitHubApi.repositories(search_expression)
29
+
30
+ Paginator.new(repositories).paginate do |repository|
31
+ repository.summary
32
+ end
33
+ end
34
+
35
+ def name
36
+ self.class.arguments.map { |a| options[a] }.compact.join(' ')
37
+ end
38
+ end
39
+ end
40
+ end