simple-cli 0.3.10 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +51 -0
- data/VERSION +1 -1
- data/doc/examples/ex1/ex1 +2 -0
- data/doc/examples/ex1/ex1.rb +41 -0
- data/lib/simple/cli/deprecations.rb +19 -0
- data/lib/simple/cli/helper/short_help.rb +1 -1
- data/lib/simple/cli/logger/colored_logger.rb +18 -3
- data/lib/simple/cli.rb +6 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f4816a86d6b802c97493e9961b17d2a3db19c3f00de186fe59b40b4de53a8cc
|
4
|
+
data.tar.gz: dc86cba3ab4c96a2c071f6bdf517c5db19e7186caaee9e8962954484139ce1ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df10c1919a31273bedac7729af01334743854afceff9feb138daf880424db897fcc006812296334d0ab08036152d4a25ac7f8a88093e1a205d0dbc935f5b1929
|
7
|
+
data.tar.gz: cc4be6f1c00b1c91664847444f31b3cfd0065df07f85d1d9a4cf8083984cf59f30b0c7aded89da189de319452fda1a063d22b315af4d0b1a62d0999367186875
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
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.
|
1
|
+
0.3.13
|
@@ -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)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ::Simple::CLI::Deprecations
|
2
|
+
SELF = self
|
3
|
+
|
4
|
+
def logger
|
5
|
+
SELF.deprecated! "Simple::CLI#logger", alternative: "Simple::CLI.logger"
|
6
|
+
end
|
7
|
+
|
8
|
+
def run!(*_)
|
9
|
+
SELF.deprecated! "Simple::CLI#run!", alternative: "Simple::CLI.run!(Your::CLI)"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.deprecated!(what, alternative: nil)
|
13
|
+
Simple::CLI.logger.error "'#{what}' was removed."
|
14
|
+
if alternative
|
15
|
+
Simple::CLI.logger.info "You probably want to use '#{alternative}' instead."
|
16
|
+
end
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
@@ -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
|
156
|
-
#
|
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
|
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/lib/simple/cli.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative "cli/adapter"
|
|
13
13
|
require_relative "cli/logger"
|
14
14
|
require_relative "cli/on_exception"
|
15
15
|
require_relative "cli/helpers"
|
16
|
+
require_relative "cli/deprecations"
|
16
17
|
|
17
18
|
require "simple/service"
|
18
19
|
|
@@ -29,6 +30,11 @@ module Simple::CLI
|
|
29
30
|
def self.included(base)
|
30
31
|
base.include(::Simple::Service)
|
31
32
|
base.include(::Simple::CLI::Helpers)
|
33
|
+
|
34
|
+
# When going from 0.2 to 0.3 we removed some helpers that originally had been
|
35
|
+
# mixed into the target CLI module. The ::Simple::CLI::Deprecations module
|
36
|
+
# makes sure to print deprecation warnings.
|
37
|
+
base.extend(::Simple::CLI::Deprecations)
|
32
38
|
end
|
33
39
|
|
34
40
|
# Runs the service with the current command line arguments.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: simple-service
|
@@ -33,14 +33,19 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
35
|
- ".rubocop.yml"
|
36
|
+
- ".ruby-version"
|
36
37
|
- Gemfile
|
38
|
+
- README.md
|
37
39
|
- Rakefile
|
38
40
|
- VERSION
|
39
41
|
- bin/rake
|
42
|
+
- doc/examples/ex1/ex1
|
43
|
+
- doc/examples/ex1/ex1.rb
|
40
44
|
- lib/simple-cli.rb
|
41
45
|
- lib/simple/cli.rb
|
42
46
|
- lib/simple/cli/adapter.rb
|
43
47
|
- lib/simple/cli/default_options.rb
|
48
|
+
- lib/simple/cli/deprecations.rb
|
44
49
|
- lib/simple/cli/helper.rb
|
45
50
|
- lib/simple/cli/helper/help.rb
|
46
51
|
- lib/simple/cli/helper/help_on_command.rb
|
@@ -77,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
82
|
- !ruby/object:Gem::Version
|
78
83
|
version: '0'
|
79
84
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.1.4
|
81
86
|
signing_key:
|
82
87
|
specification_version: 4
|
83
88
|
summary: Simple CLI builder for ruby
|