simple-cli 0.2.20 → 0.2.28

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: 2d26ea250d929404c83f6c19ea9c0a188f53f18b67184305cdf21bb543ae68d6
4
- data.tar.gz: 288e4524b2cef953b78be71745f9f41f3b1def3091f6780e6f137e4e7f4e855e
3
+ metadata.gz: ba16419e4dc2f0fe2dc47fe0a5cb29a6de15a57d2b221ef3aa8c3ed7455c0556
4
+ data.tar.gz: 6293877fe62faaaf2718745c94ebb1ea798e1500330f75095c0363f151047fe4
5
5
  SHA512:
6
- metadata.gz: 44e5a83ad0ee46147c0c5c36cb68a424f5b132a215c1e3bc0f59198e2fd38edad1a6a67aed8a7d47a95951dcd59aef0636688257c3d9a0cef5a38c74c45ac6ce
7
- data.tar.gz: 4d735d8b7b4a38c95c0ee923ab6695cff2b45ef641a28dd130598a78983785bd551f785d2d92d2f757ee8a927096b7e4d219b565e14099cbd3f82391f49bd144
6
+ metadata.gz: 1dc54fc73aa56d28485023047df277663cdf0b0edeaacde994c772fd908934e7994bf84d4f9e216cc55573df2b3ad128d800ab217f268dfdbee731fd48e0db93
7
+ data.tar.gz: b9ee91e8c0aae8d0586b90dcbebe7476d9c34338ecc45bbdd08a685548f539c519db6412e99de13a65acac5538d0c151fe2dd76b9c3966126d1c91b910ada533
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/README.md ADDED
@@ -0,0 +1,32 @@
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
+
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exec $0.rb "$@"
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/inline'
3
+
4
+ gemfile do
5
+ source 'https://rubygems.org'
6
+ gem "simple-cli", '~> 0.2', 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
+ Ex1::CLI.run!(*ARGV)
@@ -18,14 +18,17 @@ module Simple::CLI::Helpers
18
18
  ::Simple::CLI.logger
19
19
  end
20
20
 
21
- def confirm(msg)
21
+ def confirm!(msg)
22
22
  STDERR.puts <<~MSG
23
- #{msg}
23
+ #{msg.chomp}
24
24
 
25
25
  Press return to continue, ^C to cancel...
26
26
  MSG
27
27
 
28
28
  STDIN.gets
29
+ rescue Interrupt
30
+ logger.error "Cancelled by user"
31
+ exit 1
29
32
  end
30
33
 
31
34
  SSH = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
@@ -118,10 +118,25 @@ module Simple::CLI::Logger::ColoredLogger
118
118
  STDERR.puts msg
119
119
  end
120
120
 
121
- # The heuristic used to determine the caller is not perfect, but should
122
- # do well in most cases.
121
+ # [TODO] The heuristic used to determine the caller is not perfect.
122
+ # Maybe we'll find a better solution; but for now this has to do.
123
123
  def source_from_caller
124
- source = caller.find { |loc| loc !~ /simple-cli.*\/lib\/simple\/cli/ }
124
+ source = caller.find do |loc|
125
+ # skip this gem
126
+ next false if loc =~ /\/lib\/simple\/cli\//
127
+
128
+ # skip forwardable from Ruby stdlib
129
+ next false if loc =~ /\/forwardable.rb\:/
130
+
131
+ # skip simple-sql
132
+ next false if loc =~ /\/lib\/simple\/sql\b/
133
+
134
+ # skip lib/postjob/queue/postgres/checked_sql.rb
135
+ next false if loc =~ %r{lib/postjob/queue/postgres/checked_sql.rb}
136
+
137
+ true
138
+ end
139
+
125
140
  source ||= caller[2]
126
141
  source = source[(wd.length + 1)..-1] if source.start_with?(wd)
127
142
  source
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module CLI
3
- VERSION = "0.2.20"
3
+ VERSION = "0.2.28"
4
4
  end
5
5
  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.2.20
4
+ version: 0.2.28
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-07-05 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: rake
@@ -75,9 +75,13 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".rubocop.yml"
78
+ - ".ruby-version"
78
79
  - Gemfile
80
+ - README.md
79
81
  - Rakefile
80
82
  - bin/rake
83
+ - doc/examples/ex1/ex1
84
+ - doc/examples/ex1/ex1.rb
81
85
  - lib/simple-cli.rb
82
86
  - lib/simple/cli.rb
83
87
  - lib/simple/cli/adapter.rb
@@ -99,7 +103,7 @@ files:
99
103
  homepage: http://github.com/radiospiel/simple-cli
100
104
  licenses: []
101
105
  metadata: {}
102
- post_install_message:
106
+ post_install_message:
103
107
  rdoc_options: []
104
108
  require_paths:
105
109
  - lib
@@ -114,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  - !ruby/object:Gem::Version
115
119
  version: '0'
116
120
  requirements: []
117
- rubygems_version: 3.0.2
118
- signing_key:
121
+ rubygems_version: 3.1.4
122
+ signing_key:
119
123
  specification_version: 4
120
124
  summary: Simple CLI builder for ruby
121
125
  test_files: