mini-cli 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: b99c5619db31b2250da1515981cf62e897939e57399e72b44c3b48d22d4c9840
4
- data.tar.gz: 9ea02f0d1077a03ca5284ef20619a9c38370d9bcece25ba106e0b834733660c1
3
+ metadata.gz: 1e6c0c096fa96ac3c5687b159637ae5762c1dfa9d18201b0253476bfb96050ca
4
+ data.tar.gz: 21eb69f322117c7eb8cc2c810292b1b38a3a3f268356cdd9c5cd2f2d0d876a9b
5
5
  SHA512:
6
- metadata.gz: 5877c7746653b3999ec6337e86e108276f26ba9a2142bdee0892033491cce2f788ee8dea594742cc5fb0554a1496923dfe5b80eba03409e9b6b4c4f2255d2d7d
7
- data.tar.gz: 7c7d1e36a5dd1ae1f139826ad9063e68e38a864416744e383e3e308fb8d172ab6efc58c26c5e4875422884deb6e2fa820ec10cc7371d028fcdfa53b6e06523ba
6
+ metadata.gz: 5c975c9bff22c0841ac32ac6340d74ed908babb282f5791a7ed0951ad7f59fd0f4e9bcb3226a83f4dd1548ccfe340c2071072a94f4ac27e8937cae234fa584ac
7
+ data.tar.gz: c8544fba204f56ad6e2359d37ffe9e76ce9997ad34653270d1241d7c82d1153d8826e260f2f40d4840065dc70bd7133139d5cb835fbcee7394696245e825e512
data/gems.rb CHANGED
@@ -1 +1,2 @@
1
+ source 'https://rubygems.org'
1
2
  gemspec
@@ -96,6 +96,7 @@ module MiniCli
96
96
  @args.each do |arg|
97
97
  next if arg.index('..')
98
98
  value = arguments.shift
99
+
99
100
  if arg.start_with?('[')
100
101
  @result[arg[1..-2]] = value if value
101
102
  else
@@ -4,7 +4,7 @@ require 'open3'
4
4
 
5
5
  module MiniCli
6
6
  def run(*cmd)
7
- opts = Hash === cmd.last ? __run_opt(cmd.last) : [:stdout]
7
+ opts = Hash === cmd.last ? __run_opt(cmd.last) : %i[stdout]
8
8
  opts.delete(:stderr) ? __run3(opts, cmd) : __run2(opts, cmd)
9
9
  rescue SystemCallError
10
10
  nil
@@ -27,6 +27,6 @@ module MiniCli
27
27
  end
28
28
 
29
29
  def __run_opt(opts)
30
- %i[stdout stderr status].keep_if{ |s| opts.delete(s) }
30
+ %i[stdout stderr status].keep_if { |s| opts.delete(s) }
31
31
  end
32
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniCli
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -27,5 +27,5 @@ GemSpec = Gem::Specification.new do |gem|
27
27
  all_files = %x(git ls-files -z).split(0.chr)
28
28
  gem.test_files = all_files.grep(%r{^(spec|test)/})
29
29
  gem.files = all_files - gem.test_files
30
- # gem.extra_rdoc_files = %w[README.MD]
30
+ gem.extra_rdoc_files = %w[README.md]
31
31
  end
@@ -11,15 +11,12 @@ help <<~HELP, %w[TARGET [SOURCE]]
11
11
  --opt option without any argument
12
12
  HELP
13
13
 
14
- main do |cfg|
15
- cfg.each_pair{ |key, value| puts("#{key}: #{value}") }
16
- end
14
+ main { |cfg| cfg.each_pair { |key, value| puts("#{key}: #{value}") } }
17
15
 
18
16
  parse_argv do |args|
19
17
  Struct.new(:target, :sources, :name, :url, :switch, :opt).new.tap do |cfg|
20
18
  cfg.target = args['TARGET']
21
- # args['FILES'] is an array containing all surplus arguments
22
- cfg.sources = args['FILES']
19
+ cfg.sources = args['FILES'] # args['FILES'] is an array containing all surplus arguments
23
20
  source = args['SOURCE'] || ENV['SOURCE']
24
21
  cfg.sources.unshift(source) if source
25
22
  cfg.sources << 'STDIN' if cfg.sources.empty?
@@ -9,6 +9,4 @@ help <<~HELP
9
9
  This is a very simple sample without any required parameter.
10
10
  HELP
11
11
 
12
- main do |args|
13
- puts("given files: #{args['FILES']}")
14
- end
12
+ main { |args| puts("given files: #{args['FILES']}") }
@@ -11,14 +11,15 @@ class Test < Minitest::Test
11
11
  attr_reader :subject
12
12
 
13
13
  def setup
14
- @subject = Class.new do
15
- include MiniCli
16
- attr_reader :exit_args
14
+ @subject =
15
+ Class.new do
16
+ include MiniCli
17
+ attr_reader :exit_args
17
18
 
18
- def exit(*args)
19
- @exit_args = args
20
- end
21
- end.new
19
+ def exit(*args)
20
+ @exit_args = args
21
+ end
22
+ end.new
22
23
  end
23
24
 
24
25
  def assert_stop_with_error(code, text, &block)
@@ -3,21 +3,13 @@ require_relative '../helper'
3
3
  class MainTest < Test
4
4
  def test_defaults
5
5
  assert_equal('helper', subject.name)
6
- assert_output("Usage: helper\n"){ subject.show_help }
6
+ assert_output("Usage: helper\n") { subject.show_help }
7
7
  end
8
8
 
9
9
  def test_methods
10
- subject = Class.new{ include MiniCli }.new
11
-
12
- expected_methods = %i[
13
- error
14
- help
15
- main
16
- name
17
- parse_argv
18
- run
19
- show_help
20
- ].sort!
10
+ subject = Class.new { include MiniCli }.new
11
+
12
+ expected_methods = %i[error help main name parse_argv run show_help].sort!
21
13
  methods = (subject.methods - Object.new.methods).sort!
22
14
  assert_equal(expected_methods, methods)
23
15
  end
@@ -27,9 +19,7 @@ class MainTest < Test
27
19
  subject.error(42, 'some error text')
28
20
  end
29
21
 
30
- assert_stop_with_error(21, 'error') do
31
- subject.error(21, :error)
32
- end
22
+ assert_stop_with_error(21, 'error') { subject.error(21, :error) }
33
23
  end
34
24
 
35
25
  def test_help_simple
@@ -39,7 +29,7 @@ class MainTest < Test
39
29
  Some helptext
40
30
  EXPECTED
41
31
 
42
- assert_output(expected_text){ subject.show_help }
32
+ assert_output(expected_text) { subject.show_help }
43
33
  end
44
34
 
45
35
  def test_help_with_args
@@ -54,7 +44,7 @@ class MainTest < Test
54
44
  here
55
45
  EXPECTED
56
46
 
57
- assert_output(expected_text){ subject.show_help }
47
+ assert_output(expected_text) { subject.show_help }
58
48
  end
59
49
 
60
50
  def test_argument_required
@@ -64,10 +54,10 @@ class MainTest < Test
64
54
  subject.parse_argv(as_argv(''))
65
55
  end
66
56
 
67
- expected = {'ARG' => 'arg', 'FILES' => []}
57
+ expected = { 'ARG' => 'arg', 'FILES' => [] }
68
58
  assert_equal(expected, subject.parse_argv(as_argv('arg')))
69
59
 
70
- expected = {'ARG' => 'arg1', 'FILES' => %w[arg2 arg3]}
60
+ expected = { 'ARG' => 'arg1', 'FILES' => %w[arg2 arg3] }
71
61
  assert_equal(expected, subject.parse_argv(as_argv('arg1 arg2 arg3')))
72
62
  end
73
63
 
@@ -83,10 +73,10 @@ class MainTest < Test
83
73
  subject.parse_argv(as_argv(''))
84
74
  end
85
75
 
86
- expected = {'ARG1' => 'arg1', 'ARG2' => 'arg2', 'FILES' => []}
76
+ expected = { 'ARG1' => 'arg1', 'ARG2' => 'arg2', 'FILES' => [] }
87
77
  assert_equal(expected, subject.parse_argv(as_argv('arg1 arg2')))
88
78
 
89
- expected = {'ARG1' => 'arg', 'FILES' => []}
79
+ expected = { 'ARG1' => 'arg', 'FILES' => [] }
90
80
  assert_equal(expected, subject.parse_argv(as_argv('arg')))
91
81
  end
92
82
 
@@ -100,21 +90,21 @@ class MainTest < Test
100
90
  Some additional explaination can be here
101
91
  HELP
102
92
 
103
- expected = {'FILES' => []}
93
+ expected = { 'FILES' => [] }
104
94
  assert_equal(expected, subject.parse_argv(as_argv('')))
105
95
 
106
- expected = {'NAME' => 'name', 'FILES' => []}
96
+ expected = { 'NAME' => 'name', 'FILES' => [] }
107
97
  assert_equal(expected, subject.parse_argv(as_argv('--named name')))
108
98
  assert_equal(expected, subject.parse_argv(as_argv('-n name')))
109
99
 
110
- expected = {'LNAME' => 'long', 'FILES' => []}
100
+ expected = { 'LNAME' => 'long', 'FILES' => [] }
111
101
  assert_equal(expected, subject.parse_argv(as_argv('--named-long long')))
112
102
 
113
- expected = {'unnamed' => true, 'FILES' => []}
103
+ expected = { 'unnamed' => true, 'FILES' => [] }
114
104
  assert_equal(expected, subject.parse_argv(as_argv('--unnamed')))
115
105
  assert_equal(expected, subject.parse_argv(as_argv('-u')))
116
106
 
117
- expected = {'un-named' => true, 'FILES' => []}
107
+ expected = { 'un-named' => true, 'FILES' => [] }
118
108
  assert_equal(expected, subject.parse_argv(as_argv('--un-named')))
119
109
 
120
110
  expected = {
@@ -125,23 +115,14 @@ class MainTest < Test
125
115
  'FILES' => %w[FILE1 FILE2]
126
116
  }
127
117
 
128
- result = subject.parse_argv(%w[
129
- --named name
130
- --named-long long
131
- --unnamed
132
- --un-named
133
- FILE1
134
- FILE2
135
- ])
118
+ result =
119
+ subject.parse_argv(
120
+ %w[--named name --named-long long --unnamed --un-named FILE1 FILE2]
121
+ )
136
122
  assert_equal(expected, result)
137
123
 
138
- result = subject.parse_argv(%w[
139
- -nu name
140
- --named-long long
141
- --un-named
142
- FILE1
143
- FILE2
144
- ])
124
+ result =
125
+ subject.parse_argv(%w[-nu name --named-long long --un-named FILE1 FILE2])
145
126
  assert_equal(expected, result)
146
127
  end
147
128
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-09 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,10 +56,11 @@ description: |
56
56
  This gem is a lean, easy to use CLI framework with a very small footprint.
57
57
  It provides an easy to use argument parsing, help displaying and
58
58
  minimalistic error handling.
59
- email:
59
+ email:
60
60
  executables: []
61
61
  extensions: []
62
- extra_rdoc_files: []
62
+ extra_rdoc_files:
63
+ - README.md
63
64
  files:
64
65
  - ".gitignore"
65
66
  - README.md
@@ -80,7 +81,7 @@ licenses: []
80
81
  metadata:
81
82
  source_code_uri: https://github.com/mblumtritt/mini-cli
82
83
  bug_tracker_uri: https://github.com/mblumtritt/mini-cli/issues
83
- post_install_message:
84
+ post_install_message:
84
85
  rdoc_options: []
85
86
  require_paths:
86
87
  - lib
@@ -95,8 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubygems_version: 3.1.2
99
- signing_key:
99
+ rubygems_version: 3.1.4
100
+ signing_key:
100
101
  specification_version: 4
101
102
  summary: The lean CLI framework for Ruby
102
103
  test_files: