simple-cli 0.3.8 → 0.3.12

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: 0fe90f1db0d7da40f484573c95ee3b534dcd2e60b1ffe33e12beef901f134a7c
4
- data.tar.gz: 6f4d4c221df0642d2e9873770c75520ce2a629f41b2d64fb225c75f07f17948d
3
+ metadata.gz: 156fbfd11f78c47d66f43a6c6158377ec51f5f20061e16fa5c5b853a1d622fcc
4
+ data.tar.gz: aa0e7b9585e559377362197e6a094f8023a0e8293d6974d175f335bd99ed75ed
5
5
  SHA512:
6
- metadata.gz: 8cf8cf8ab7e644dd633d60f0fb9bfd418453340f210a8b49ebd2713af589e472e052d39779f43e0adba3e11c4c7f2d311b6669acb3ed94fbe3a96f48bb5b093d
7
- data.tar.gz: 1b0183a301605c9996efba79a8c2fb8f5fe2aacd241d074b97b5d5c9f367f0c45dc6566ba13f79b806f43c670f60471cb6b1d4264b6d444d76e311060d8afc0d
6
+ metadata.gz: fdb819a5b2fd0cebc5f3359ddbd18992b690779eee27fe673018c659372f232c8b70839f6dbdb33f71901bf9242da3a70e3792234df5e6d5e2aaab2d64949dd9
7
+ data.tar.gz: 1c81fd6b778df6e551a055074b7cb3c38cfb120d27f9f4e25cf74e17d6d33036f1663a0b8d611407efd719ab10c45730061bbab813a09a045c86ca078f7a38de
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/Gemfile CHANGED
@@ -3,4 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in {gemname}.gemspec
4
4
  gemspec
5
5
 
6
- # gem "simple-service", path: "../simple-service"
6
+ # development gems
7
+ gem 'rake', '~> 12'
8
+ gem 'rspec', '~> 3.7'
9
+ gem 'simplecov', '~> 0'
10
+ gem 'rubocop', '= 0.52.1'
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # simple-cli
2
+
3
+ Building Ruby CLIs with easy.
4
+
5
+ ## Philosophy
6
+
7
+ Building a command line could be much easier than what ruby provides with its standard library. In general, between the invocation of a tool from the command line and the actual running of whatever code the user intends to run really should disappear.
8
+
9
+ Ideally a developer would only have to build the implementation of whatever logic should be provided by the tool; everything else - parsing arguments, calling the tool's implementation, printing help - should happen automatically.
10
+
11
+ This is roughly what sinmple-sql provides.
12
+
13
+ ## On versions
14
+
15
+ `simple-cli` is still on a 0.x.x version, and, generally, a 0.x.y version is not compatible with a 0.x+1.y version.
16
+
17
+ These are the follow
18
+
19
+ - The 0.2.x versions are tracked in the [`stable`](https://github.com/radiospiel/simple-cli/tree/stable) branch
20
+ - The 0.3.x versions are tracked in the [`master`](https://github.com/radiospiel/simple-cli/tree/stable) branch
21
+
22
+ ## Basic features
23
+
24
+ - build command line features in a number of modules;
25
+ - public methods in these modules provide a subcommand for the CLI;
26
+ - `"_"` in the method name are being mapped to `":"` in the CLI;
27
+ - CLI provides a help subcommand. help texts are derived from the methods over a subcommand implementation:
28
+ - The first line determines the "short help" message, to be included in the `$CMD help` command list;
29
+ - The remaining lines determines the full help message, to be included in the `$CMD help subcommand` message.
30
+
31
+ ## Example
32
+
33
+ An example can be found in [./doc/examples/ex1](./doc/examples/ex1)
34
+
35
+ ## Use logging
36
+
37
+ `Simple::CLI` provides a logger instance. This is configured to write to STDERR, and to use colors for different log levels. By default the logger is configured to run on INFO log levels. With the `--quiet` flag the logger is running at WARN log level; the `--verbose` command line flag runs the logger on DEBUG log level, and also includes the source position of calling log.
38
+
39
+ ## Updating to version 0.3
40
+
41
+ While the 0.2 version is still perfectly functional, its last version was released on Jul 5th, 2019. Development on the 0.3 versions started with some refactoring: the logic that inspects a subcommand invocation and determines its argument names and default types has been moved to a `simple-services' gem.
42
+
43
+ To upgrade from simple-cli version 0.2 to version 0.3 all you typically have to do is to replace the
44
+
45
+ YourApp::CLI.run!(*ARGV)
46
+
47
+ invocation with
48
+
49
+ Simple::CLI.run!(YourApp::CLI)
50
+
51
+ This [commit](https://github.com/radiospiel/simple-cli/commit/3e75bd6fb913a2b458269c91597c42cabac226b4) provides an example of doing that.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.12
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exec $0.rb "$@"
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/inline'
3
+
4
+ gemfile do
5
+ source 'https://rubygems.org'
6
+ gem "simple-cli", '~> 0.3', path: "../../.."
7
+ end
8
+
9
+ module Ex1; end
10
+ module Ex1::CLI
11
+ include Simple::CLI
12
+
13
+ # Command without arguments
14
+ #
15
+ # Example:
16
+ #
17
+ # ./ex1 hello:world
18
+ #
19
+ def hello_world
20
+ puts "Hello from #{__FILE__}"
21
+ end
22
+
23
+ # Command with arguments
24
+ #
25
+ # This implements a command with arguments
26
+ #
27
+ # Examples:
28
+ #
29
+ # ./ex1 hello --name=user "what's up"
30
+ #
31
+ def hello(message, name: nil)
32
+ if name
33
+ puts "Hello #{name}: #{message}!"
34
+ else
35
+ puts "Hello, #{message}!"
36
+ end
37
+ end
38
+ end
39
+
40
+ $0 = "ex1"
41
+ Simple::CLI.run!(Ex1::CLI)
@@ -2,13 +2,13 @@ module Simple::CLI
2
2
  module Helper
3
3
  def help!(service, verbose:)
4
4
  STDERR.puts <<~MSG
5
- #{H.binary_name} <command> [ options... ]
5
+ #{H.binary_name} <subcommand> [ options... ]
6
6
 
7
- Commands:
7
+ Subcommands:
8
8
 
9
9
  #{format_usages usages(service, verbose: verbose), prefix: " "}
10
10
 
11
- Default options and commands include:
11
+ Default options and subcommands include:
12
12
 
13
13
  #{format_usages default_usages(service, verbose: verbose), prefix: " "}
14
14
 
@@ -36,7 +36,7 @@ module Simple::CLI
36
36
 
37
37
  options = action.parameters.select(&:keyword?).map do |param|
38
38
  if param.required?
39
- "--#{name}=<#{name}>"
39
+ "--#{param.name}=<#{param.name}>"
40
40
  else
41
41
  case param.default_value
42
42
  when false then "[ --#{param.name} ]"
@@ -8,16 +8,32 @@ module Simple::CLI
8
8
  actions, hidden_actions = actions.partition(&:short_description)
9
9
 
10
10
  STDERR.puts <<~MSG
11
- #{H.binary_name} <command> [ options... ]
11
+ #{H.binary_name} <subcommand> [ options... ]
12
12
 
13
13
  MSG
14
14
 
15
- subcommands = actions.map { |action| "'" + H.action_to_command(action.name) + "'" }
16
- msg = "Subcommands include #{subcommands.sort.join(", ")}"
17
- msg += " (and an additional #{hidden_actions.count} internal commands)"
15
+ # if we don't have too many subcommands we print them here. If not, we only print their names
16
+ # and mention the help command.
17
+ if actions.count < 8
18
+ STDERR.puts <<~MSG
19
+ Subcommands:
20
+
21
+ #{format_usages usages(service, verbose: false), prefix: " "}
22
+
23
+ MSG
24
+ else
25
+ subcommands = actions.map { |action| "'" + H.action_to_command(action.name) + "'" }
26
+ msg = "Subcommands include #{subcommands.sort.join(", ")}"
27
+ msg += " (and, in addition, #{hidden_actions.count} internal commands)" if hidden_actions.count > 0
28
+
29
+ STDERR.puts <<~MSG
30
+ #{msg}. Run with "-h" for more details.
31
+
32
+ MSG
33
+ end
18
34
 
19
35
  STDERR.puts <<~MSG
20
- #{msg}. Default options and commands include:
36
+ Default options and subcommands include:
21
37
 
22
38
  #{format_usages default_usages(service, verbose: false), prefix: " "}
23
39
 
@@ -152,10 +152,25 @@ module Simple::CLI::Logger::ColoredLogger
152
152
  Pathname.new(absolute_path).relative_path_from(@pwd_pathname).to_s
153
153
  end
154
154
 
155
- # The heuristic used to determine the caller is not perfect, but should
156
- # do well in most cases.
155
+ # [TODO] The heuristic used to determine the caller is not perfect.
156
+ # Maybe we'll find a better solution; but for now this has to do.
157
157
  def source_from_caller
158
- source = caller.find { |loc| loc !~ /simple-cli.*\/lib\/simple\/cli/ }
158
+ source = caller.find do |loc|
159
+ # skip this gem
160
+ next false if loc =~ /\/lib\/simple\/cli\//
161
+
162
+ # skip forwardable from Ruby stdlib
163
+ next false if loc =~ /\/forwardable.rb\:/
164
+
165
+ # skip simple-sql
166
+ next false if loc =~ /\/lib\/simple\/sql\b/
167
+
168
+ # skip lib/postjob/queue/postgres/checked_sql.rb
169
+ next false if loc =~ %r{lib/postjob/queue/postgres/checked_sql.rb}
170
+
171
+ true
172
+ end
173
+
159
174
  source ||= caller[2]
160
175
  source = source[(wd.length + 1)..-1] if source.start_with?(wd)
161
176
  source
data/simple-cli.gemspec CHANGED
@@ -28,10 +28,4 @@ Gem::Specification.new do |gem|
28
28
 
29
29
  # optional gems (required by some of the parts)
30
30
  gem.add_dependency "simple-service", "~> 0.1.5"
31
-
32
- # development gems
33
- gem.add_development_dependency 'rake', '~> 12'
34
- gem.add_development_dependency 'rspec', '~> 3.7'
35
- gem.add_development_dependency 'simplecov', '~> 0'
36
- gem.add_development_dependency 'rubocop', '= 0.52.1'
37
31
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  - mediapeers GmbH
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-25 00:00:00.000000000 Z
12
+ date: 2021-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simple-service
@@ -25,62 +25,6 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.1.5
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '12'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '12'
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '3.7'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.7'
56
- - !ruby/object:Gem::Dependency
57
- name: simplecov
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: rubocop
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - '='
75
- - !ruby/object:Gem::Version
76
- version: 0.52.1
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - '='
82
- - !ruby/object:Gem::Version
83
- version: 0.52.1
84
28
  description: Simple CLI builder
85
29
  email: eno@radiospiel.org
86
30
  executables: []
@@ -89,10 +33,14 @@ extra_rdoc_files: []
89
33
  files:
90
34
  - ".gitignore"
91
35
  - ".rubocop.yml"
36
+ - ".ruby-version"
92
37
  - Gemfile
38
+ - README.md
93
39
  - Rakefile
94
40
  - VERSION
95
41
  - bin/rake
42
+ - doc/examples/ex1/ex1
43
+ - doc/examples/ex1/ex1.rb
96
44
  - lib/simple-cli.rb
97
45
  - lib/simple/cli.rb
98
46
  - lib/simple/cli/adapter.rb
@@ -118,7 +66,7 @@ files:
118
66
  homepage: http://github.com/radiospiel/simple-cli
119
67
  licenses: []
120
68
  metadata: {}
121
- post_install_message:
69
+ post_install_message:
122
70
  rdoc_options: []
123
71
  require_paths:
124
72
  - lib
@@ -133,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
81
  - !ruby/object:Gem::Version
134
82
  version: '0'
135
83
  requirements: []
136
- rubygems_version: 3.0.2
137
- signing_key:
84
+ rubygems_version: 3.1.4
85
+ signing_key:
138
86
  specification_version: 4
139
87
  summary: Simple CLI builder for ruby
140
88
  test_files: