simple-cli 0.3.11 → 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: bc691567bf3582bb69161dbb06a43e0de48ef933d21d7b56023799faf4b29396
4
- data.tar.gz: 552cc00e73471be8ada665440cc2821a75f7b71897dfc1cde47d216aa7561ce2
3
+ metadata.gz: 156fbfd11f78c47d66f43a6c6158377ec51f5f20061e16fa5c5b853a1d622fcc
4
+ data.tar.gz: aa0e7b9585e559377362197e6a094f8023a0e8293d6974d175f335bd99ed75ed
5
5
  SHA512:
6
- metadata.gz: 5203645bb10980c42223ed37ea70825d06224f95a4dd5372e145eca00d6a89bbf1548d403c10e0e02b5c60661cbe8cf5a65325deacb62558241d78e27e3564bb
7
- data.tar.gz: c794abd7680ae85694104792c2a96d940483263f170b3706b0136a8795edb7ad49199e8ed67ea12dad39405a8df6df97ddb719e20f83a8158e88feb508bde3bc
6
+ metadata.gz: fdb819a5b2fd0cebc5f3359ddbd18992b690779eee27fe673018c659372f232c8b70839f6dbdb33f71901bf9242da3a70e3792234df5e6d5e2aaab2d64949dd9
7
+ data.tar.gz: 1c81fd6b778df6e551a055074b7cb3c38cfb120d27f9f4e25cf74e17d6d33036f1663a0b8d611407efd719ab10c45730061bbab813a09a045c86ca078f7a38de
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.11
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)
@@ -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
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.11
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: 2020-03-31 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
@@ -33,10 +33,14 @@ 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
@@ -62,7 +66,7 @@ files:
62
66
  homepage: http://github.com/radiospiel/simple-cli
63
67
  licenses: []
64
68
  metadata: {}
65
- post_install_message:
69
+ post_install_message:
66
70
  rdoc_options: []
67
71
  require_paths:
68
72
  - lib
@@ -77,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
81
  - !ruby/object:Gem::Version
78
82
  version: '0'
79
83
  requirements: []
80
- rubygems_version: 3.0.6
81
- signing_key:
84
+ rubygems_version: 3.1.4
85
+ signing_key:
82
86
  specification_version: 4
83
87
  summary: Simple CLI builder for ruby
84
88
  test_files: