simple_commander 0.5.1 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c113def76d8e2c42c52c1bc2caca6d82e0fe3bb
4
- data.tar.gz: 11b4ee0a7734d55fbcf553c7972c3f1694ffb2fc
3
+ metadata.gz: 65ae721633a7c35d977c9b033a4bca2870dba042
4
+ data.tar.gz: 636b93e741d7e7873a609473a42943ce7c4db9ff
5
5
  SHA512:
6
- metadata.gz: d9299cd58523a1f83da2581f1ce61ff145fb6e609b4fd8ceed7375b1e366a2f03664bd2d9bb94da40141820606ea4ca6f8fca02d69c52e8f9c36a4c5001cdb96
7
- data.tar.gz: de14a10006f8485c50eeb8a5559f62abfa7b3f9763f8eda6dface9fd851bba5a7564e0b99e2f1f63f1465dce22cbfa20a99dd882dd98143a5f7c805076f82448
6
+ metadata.gz: 2d965537a7a799d382f0537929abe7ac4f96cc1456062768abded51706c596f81769534f5bb6389c62f46664eae778e62873ddef44a36e7de3caccd68bd0b763
7
+ data.tar.gz: 379d4b8941d1d8174611d1496c372ea4307b89e6e92c41ed0efd47df70d79ec4ded11239c22c2054fc95240730108af0979e0bbf816033335f8d3d1602f35d64
@@ -1,4 +1,16 @@
1
1
  c
2
+ n
3
+ exec_path
4
+ c
5
+ exec_path.empty?
6
+ @config_file
7
+ exec_path
8
+ c
9
+ n
10
+ if exec_path then puts 'exec path' end
11
+ if exec_path
12
+ exec_path
13
+ c
2
14
  yml
3
15
  c
4
16
  s_path
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
  gem 'codeclimate-test-reporter', group: :test, require: nil
5
+ gem 'colorized'
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_commander (0.5.1)
5
+ highline (~> 1.7.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.3.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ codeclimate-test-reporter (1.0.3)
14
+ simplecov
15
+ colorized (0.0.0)
16
+ diff-lcs (1.2.5)
17
+ docile (1.1.5)
18
+ highline (1.7.8)
19
+ json (2.0.2)
20
+ parser (2.3.3.1)
21
+ ast (~> 2.2)
22
+ powerpack (0.1.1)
23
+ rainbow (2.1.0)
24
+ rake (12.0.0)
25
+ rspec (3.5.0)
26
+ rspec-core (~> 3.5.0)
27
+ rspec-expectations (~> 3.5.0)
28
+ rspec-mocks (~> 3.5.0)
29
+ rspec-core (3.5.4)
30
+ rspec-support (~> 3.5.0)
31
+ rspec-expectations (3.5.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-mocks (3.5.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.5.0)
37
+ rspec-support (3.5.0)
38
+ rubocop (0.29.1)
39
+ astrolabe (~> 1.3)
40
+ parser (>= 2.2.0.1, < 3.0)
41
+ powerpack (~> 0.1)
42
+ rainbow (>= 1.99.1, < 3.0)
43
+ ruby-progressbar (~> 1.4)
44
+ ruby-progressbar (1.8.1)
45
+ simplecov (0.12.0)
46
+ docile (~> 1.1.0)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ codeclimate-test-reporter
56
+ colorized
57
+ rake
58
+ rspec (~> 3.2)
59
+ rubocop (~> 0.29.1)
60
+ simple_commander!
61
+ simplecov
62
+
63
+ BUNDLED WITH
64
+ 1.12.5
@@ -1,3 +1,6 @@
1
+ === 0.6.0 / 22-12-2016
2
+ * helpers folder now stay outside of the projects
3
+
1
4
  === 0.5.1 / 28-10-2016
2
5
  * bug with config.yml solved
3
6
 
@@ -1,7 +1,13 @@
1
+ require 'colorize'
1
2
  require 'erb'
2
3
 
3
4
  module IO_helper
4
- def run_cmd(path)
5
+ def run_cmd(command)
6
+ puts "running command: #{command}".colorize(:light_green)
7
+ puts `#{command}`
8
+ end
9
+
10
+ def run_in(path)
5
11
  FileUtils.cd(path) do
6
12
  yield
7
13
  end
@@ -9,41 +15,48 @@ module IO_helper
9
15
 
10
16
  def mkdir(dest)
11
17
  if(File.directory?(dest))
12
- puts "#{dest} already exist!"
18
+ puts "mkdir ERROR: #{dest} already exist!".colorize(:red)
13
19
  return 0
14
20
  end
21
+ puts "Creating folder #{dest}".colorize(:blue)
15
22
  FileUtils.mkdir(dest)
16
23
  end
17
24
 
18
25
  def copy(src, dest)
26
+ puts "Copying from #{src} to #{dest}".colorize(:green)
19
27
  FileUtils.cp(src, dest)
20
28
  end
21
29
 
22
30
  def copy_dir(src, dest)
31
+ puts "Copying from #{src} to #{dest}".colorize(:green)
23
32
  FileUtils.copy_entry(src, dest)
24
33
  end
25
34
 
26
- def template(src, dest, replace=false)
35
+ def template(src, dest, context, replace=true)
27
36
  if(File.file?(dest) and !replace)
28
- puts "#{dest} already exist!"
37
+ puts "template ERROR: #{dest} already exist!".colorize(:red)
29
38
  return 0
30
39
  end
40
+ puts "template from #{src} to #{dest} replace: #{replace}".colorize(:magenta)
31
41
  template = File.open(src, 'r')
32
42
  file_contents = template.read
33
43
  template.close
34
44
  renderer = ERB.new(file_contents)
35
- result = renderer.result(binding)
45
+ result = renderer.result(context)
36
46
  output = File.open(dest, 'w+')
37
47
  output.write(result)
38
48
  output.close
39
49
  end
40
50
 
41
51
  def rm_file(path)
52
+ puts "rm file #{path}".colorize(:light_red)
42
53
  FileUtils.remove_file path
43
54
  end
44
55
 
56
+ # remove folder recursively
45
57
  def rm_dir(path)
46
- FileUtils.rmdir path
58
+ puts "rm dir #{path}".colorize(:light_red)
59
+ FileUtils.rm_rf path
47
60
  end
48
61
 
49
62
  def in_file?(string, path)
@@ -53,6 +66,7 @@ module IO_helper
53
66
  end
54
67
 
55
68
  def write_start(string, path)
69
+ puts "Trying to write at the start #{string[0...8]} ... on the file #{path}".colorize(:magenta)
56
70
  lines = []
57
71
  File.open(path, 'r'){|f| lines = f.readlines }
58
72
  lines.unshift("#{string}\n")
@@ -60,6 +74,7 @@ module IO_helper
60
74
  end
61
75
 
62
76
  def write_end(string, path)
77
+ puts "Trying to write at the end #{string[0...8]} ... on the file #{path}".colorize(:magenta)
63
78
  lines = []
64
79
  File.open(path, 'r'){|f| lines = f.readlines }
65
80
  lines << "#{string}\n"
@@ -67,6 +82,7 @@ module IO_helper
67
82
  end
68
83
 
69
84
  def write_after(id, string, path)
85
+ puts "Trying to write after #{id} the string #{string[0...8]} ... on the file #{path}".colorize(:magenta)
70
86
  lines = []
71
87
  File.open(path, 'r'){|f| lines = f.readlines }
72
88
  new_lines = lines.inject([]) do |result, value|
@@ -81,6 +97,7 @@ module IO_helper
81
97
  end
82
98
 
83
99
  def rm_string(string, path)
100
+ puts "Removing #{string[0...8]} from #{path}".colorize(:light_red)
84
101
  regexp = Regexp.new string
85
102
  lines = []
86
103
  File.open(path, 'r'){|f| lines = f.readlines }
@@ -89,6 +106,7 @@ module IO_helper
89
106
  end
90
107
 
91
108
  def rm_block(start_id, end_id, path)
109
+ puts "Removing string block from #{start_id} to #{end_id} #{path}".colorize(:light_red)
92
110
  start_regexp = Regexp.new start_id
93
111
  end_regexp = Regexp.new end_id
94
112
  lines, new_lines, result = [], [], true
@@ -62,31 +62,37 @@ simple_commander init
62
62
  fail InvalidProgram, "program #{args[0]} already exists!", caller if File.directory?(s_path)
63
63
  @program_name = args[0]
64
64
  @lib_path = "#{s_path}/lib"
65
- @helper_path = "#{s_path}/helpers"
65
+ @helper_path = File.expand_path "#{s_path}" + "/../helpers"
66
+
66
67
  mkdir s_path
67
68
  mkdir "#{s_path}/bin"
68
69
  mkdir "#{s_path}/spec"
69
70
  mkdir "#{s_path}/lib"
70
- mkdir "#{s_path}/helpers"
71
+ mkdir @helper_path
71
72
  mkdir "#{s_path}/lib/#{@program_name}"
72
73
  template "#{TEMPLATE_PATH}/lib.erb",
73
- "#{s_path}/lib/#{@program_name}.rb"
74
+ "#{s_path}/lib/#{@program_name}.rb", binding
74
75
 
75
76
  template "#{TEMPLATE_PATH}/version.erb",
76
- "#{s_path}/lib/#{@program_name}/version.rb"
77
+ "#{s_path}/lib/#{@program_name}/version.rb", binding
77
78
 
78
79
  template "#{TEMPLATE_PATH}/bin.erb",
79
- "#{s_path}/bin/#{@program_name}"
80
+ "#{s_path}/bin/#{@program_name}", binding
80
81
  FileUtils.chmod "+x", "#{s_path}/bin/#{@program_name}"
81
82
  copy "#{s_path}/bin/#{@program_name}", exec_path if exec_path
82
- copy "#{HELPERS_PATH}/io_helper.rb", "#{s_path}/helpers/io_helper.rb"
83
- copy "#{HELPERS_PATH}/http_helper.rb", "#{s_path}/helpers/http_helper.rb"
83
+ copy "#{HELPERS_PATH}/io_helper.rb", "#{@helper_path}/io_helper.rb"
84
+ copy "#{HELPERS_PATH}/http_helper.rb", "#{@helper_path}/http_helper.rb"
84
85
  end
85
86
 
86
87
  ##
87
88
  # if set the bin/executable* file of any program created will be put in this folder
88
89
  def exec_path
89
- YAML.load_file(@config_file)[:exec_path]
90
+ path = YAML.load_file(@config_file)[:exec_path]
91
+ if(path.empty?)
92
+ return false
93
+ else
94
+ return path
95
+ end
90
96
  end
91
97
 
92
98
  ##
@@ -1,3 +1,3 @@
1
1
  ---
2
- :path: ""
3
- :exec_path: ""
2
+ :path: "/Users/marcell/Documents/github/simple_commander/spec/mock"
3
+ :exec_path: ''
@@ -1,3 +1,3 @@
1
1
  module SimpleCommander
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ['lib']
17
17
  s.license = 'MIT'
18
18
  s.add_runtime_dependency('highline', '~> 1.7.2')
19
+ s.add_runtime_dependency('colorized', '~> 0.8.1')
19
20
  s.add_development_dependency('rspec', '~> 3.2')
20
21
  s.add_development_dependency('rake')
21
22
  s.add_development_dependency('simplecov')
@@ -28,7 +28,8 @@ describe SimpleCommander::Command do
28
28
 
29
29
  describe '#option' do
30
30
  it 'should add options' do
31
- expect { @command.option '--recursive' }.to change(@command.options, :length).from(1).to(2)
31
+ expect { @command.option '--recursive' }.to
32
+ change(@command.options, :length).from(1).to(2)
32
33
  end
33
34
 
34
35
  it 'should allow procs as option handlers' do
@@ -44,6 +45,12 @@ describe SimpleCommander::Command do
44
45
  end
45
46
 
46
47
  describe '#run' do
48
+ describe 'should call the right nested command' do
49
+ it 'calls the right nested command' do
50
+ @nested_command.run ''
51
+ end
52
+ end
53
+
47
54
  describe 'should invoke #when_called' do
48
55
  it 'with arguments seperated from options' do
49
56
  @command.when_called { |args, _options| expect(args.join(' ')).to eq('just some args') }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift "/Users/marcell/Documents/github/simple_commander/spec/mock/test_program/lib"
3
+ $LOAD_PATH.unshift "/Users/marcell/Documents/github/simple_commander/spec/mock/test_program/helpers"
4
+ require 'rubygems'
5
+ require 'simple_commander/import'
6
+ require 'simple_commander/import'
7
+ require 'io_helper'
8
+ require 'http_helper'
9
+
10
+
11
+ require 'test_program'
@@ -0,0 +1,5 @@
1
+ module HTTP_helper
2
+ def http_get
3
+ say "HTTP GET"
4
+ end
5
+ end
@@ -0,0 +1,128 @@
1
+ require 'erb'
2
+
3
+ module IO_helper
4
+ def run_cmd(path)
5
+ FileUtils.cd(path) do
6
+ yield
7
+ end
8
+ end
9
+
10
+ def mkdir(dest)
11
+ if(File.directory?(dest))
12
+ puts "#{dest} already exist!"
13
+ return 0
14
+ end
15
+ FileUtils.mkdir(dest)
16
+ end
17
+
18
+ def copy(src, dest)
19
+ FileUtils.cp(src, dest)
20
+ end
21
+
22
+ def copy_dir(src, dest)
23
+ FileUtils.copy_entry(src, dest)
24
+ end
25
+
26
+ def template(src, dest, replace=false)
27
+ if(File.file?(dest) and !replace)
28
+ puts "#{dest} already exist!"
29
+ return 0
30
+ end
31
+ template = File.open(src, 'r')
32
+ file_contents = template.read
33
+ template.close
34
+ renderer = ERB.new(file_contents)
35
+ result = renderer.result(binding)
36
+ output = File.open(dest, 'w+')
37
+ output.write(result)
38
+ output.close
39
+ end
40
+
41
+ def rm_file(path)
42
+ FileUtils.remove_file path
43
+ end
44
+
45
+ def rm_dir(path)
46
+ FileUtils.rmdir path
47
+ end
48
+
49
+ def in_file?(string, path)
50
+ regexp, content = Regexp.new string
51
+ File.open(path, 'r'){|f| content = f.read }
52
+ content =~ regexp
53
+ end
54
+
55
+ def write_start(string, path)
56
+ lines = []
57
+ File.open(path, 'r'){|f| lines = f.readlines }
58
+ lines.unshift("#{string}\n")
59
+ File.open(path, 'w+'){|f| f.write(lines.join)}
60
+ end
61
+
62
+ def write_end(string, path)
63
+ lines = []
64
+ File.open(path, 'r'){|f| lines = f.readlines }
65
+ lines << "#{string}\n"
66
+ File.open(path, 'w+'){|f| f.write(lines.join)}
67
+ end
68
+
69
+ def write_after(id, string, path)
70
+ lines = []
71
+ File.open(path, 'r'){|f| lines = f.readlines }
72
+ new_lines = lines.inject([]) do |result, value|
73
+ if value.include? id
74
+ result << value
75
+ result << "#{string}\n"
76
+ else
77
+ result << value
78
+ end
79
+ end
80
+ File.open(path, 'w+'){|f| f.write(new_lines.join)}
81
+ end
82
+
83
+ def rm_string(string, path)
84
+ regexp = Regexp.new string
85
+ lines = []
86
+ File.open(path, 'r'){|f| lines = f.readlines }
87
+ new_lines = lines.reject{|line| line =~ regexp }
88
+ File.open(path, 'w+'){|f| f.write(new_lines.join)}
89
+ end
90
+
91
+ def rm_block(start_id, end_id, path)
92
+ start_regexp = Regexp.new start_id
93
+ end_regexp = Regexp.new end_id
94
+ lines, new_lines, result = [], [], true
95
+ File.open(path, 'r'){|f| lines = f.readlines }
96
+ lines.chunk { |line|
97
+ if line =~ start_regexp
98
+ result = false
99
+ elsif line =~ end_regexp
100
+ result = true
101
+ end
102
+ result
103
+ }.each{ |result, arr|
104
+ if result
105
+ arr[0] =~ end_regexp ? arr.shift : arr
106
+ new_lines << arr
107
+ end
108
+ }
109
+ File.open(path, 'w+'){|f| f.write(new_lines.join)}
110
+ end
111
+
112
+ def cli_exist?(path, cli)
113
+ File.directory?("#{path}/#{cli}")
114
+ end
115
+
116
+ def command_exist?(path, command)
117
+ File.file?("#{path}/subcommands/#{command}.rb")
118
+ end
119
+
120
+ def subcommand_exist?(path, command, subcommand)
121
+ File.file?("#{path}/subcommands/#{command}/#{command}_#{subcommand}.rb")
122
+ end
123
+
124
+ def have_subcommands?(path, cli, command)
125
+ in_file? /register/,
126
+ "#{path}/#{cli}/subcommands/#{command}.rb"
127
+ end
128
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_program/version'
2
+
3
+ program :name, 'test_program'
4
+ program :version, Test_program::VERSION
5
+ program :description, 'test_program utility program.'
6
+ helpers 'IO'
@@ -0,0 +1,3 @@
1
+ module Test_program
2
+ VERSION = '0.0.1'
3
+ end
@@ -40,6 +40,12 @@ def create_test_command
40
40
  end
41
41
  end
42
42
  @command = command :test
43
+
44
+ command :nested do
45
+ command :test do
46
+ end
47
+ end
48
+ @nested_command = command :nested
43
49
  end
44
50
 
45
51
  # Create a new command runner
data/test.rb CHANGED
@@ -1,8 +1,4 @@
1
- require 'yaml'
2
- require 'byebug'
3
- yml = YAML.load_file('./config.yml')
4
- if(yml.key?('path'))
5
- puts 'obj have key'
6
- else
7
- puts 'obj dont have key'
8
- end
1
+ require 'colorize'
2
+
3
+ puts String.colors
4
+ puts "testig colorize".colorize(:blue)
data/todo.yml CHANGED
@@ -1,12 +1,16 @@
1
1
  cli:
2
- release a new version
3
- create the ember-generate program with the new version
2
+ creating ember generate on sc_scripts/em
4
3
  set up a default templated path for newly created programs
4
+ create the ember-generate program with the new version
5
5
  make writing tests easy
6
6
  change docs to tell to require on the bin file newly created helpers
7
7
  realease a new version and test its functionalities
8
8
  identify if the name of the program is permited
9
9
  test the new version on windows
10
+ avoid nesting commands for now, focus and finishing ember and rails commands
11
+ bug when using nested commands with the same name, only the last definition
12
+ testing how the nesting of commands works,
13
+ using spec_helper and running tests is called
10
14
 
11
15
  release:
12
16
  march 2017
@@ -29,6 +33,7 @@ learn about the implementation of the commander progress bar
29
33
  figuring out the progress bar
30
34
 
31
35
  done:
36
+ release a new version
32
37
  make the newly created command work property
33
38
  put command in the path of the new program
34
39
  make overwrite the default helpers easy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcell Monteiro Cruz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorized
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,7 @@ files:
94
108
  - ".travis.yml"
95
109
  - DEVELOPMENT
96
110
  - Gemfile
111
+ - Gemfile.lock
97
112
  - History.rdoc
98
113
  - LICENSE
99
114
  - Manifest
@@ -145,6 +160,11 @@ files:
145
160
  - spec/help_formatters/terminal_spec.rb
146
161
  - spec/methods_spec.rb
147
162
  - spec/mock/config_without_path.yml
163
+ - spec/mock/test_program/bin/test_program
164
+ - spec/mock/test_program/helpers/http_helper.rb
165
+ - spec/mock/test_program/helpers/io_helper.rb
166
+ - spec/mock/test_program/lib/test_program.rb
167
+ - spec/mock/test_program/lib/test_program/version.rb
148
168
  - spec/runner_spec.rb
149
169
  - spec/spec_helper.rb
150
170
  - spec/ui_spec.rb
@@ -152,7 +172,6 @@ files:
152
172
  - templates/lib.erb
153
173
  - templates/version.erb
154
174
  - test.rb
155
- - test2.rb
156
175
  - todo.yml
157
176
  homepage: https://github.com/0000marcell/simple_commander
158
177
  licenses:
data/test2.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'yaml'
2
-
3
- yaml = YAML.load_file('config.yml')
4
- puts yaml[:path]
5
- yml = {path: '/Users/marcell', this: 'this', that: 'that'}.to_yaml #
6
- File.open('config.yml', 'w') do |file|
7
- file.write(yml)
8
- end