cl 0.1.3 → 0.1.4

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: 7f989a757e92bffbfc45652517bbec98cc8cdd09b9aa6809e4822c807de4c3cd
4
- data.tar.gz: e315d830caf5e61f236d962d83d25c4a3e45c04e6672189a8358ad04c7007e2c
3
+ metadata.gz: 531d9fab776f1d706d8c86d087528b1a889f3511197ae5cad48d8c75a6a8aa1d
4
+ data.tar.gz: f1090e76ddfa1d0cec7a3b054b140eb6d56934ba34db6dfb7deb230eabc26f12
5
5
  SHA512:
6
- metadata.gz: d9ad4c4d902a66dbe56581053ca7babeca533a65af31d22ff815f17f9f2a386fa238fe9686af776a0df510d7cd1a6696fd32b3fc3061d9cda00f22130bcb520a
7
- data.tar.gz: 4554e81d0a53997506257670514195e1df150c8d8fe51e35bb956e40e7216d211139ae98403d9c25d05fbc66feff35eaec31471252e78a5555ff88aa2644f947
6
+ metadata.gz: 5aa9ba9d3938ac7ca67e138e3f265f3d15ec1e0aad66f7102fe3c2ac1577be3edd2565d1edec045d79d420d5d62e7c833f3fb1e130d410684a441e7c7b44f992
7
+ data.tar.gz: 82c15f26babdf980a89436e215837e2a54f161a32657764318657a3c45ec8ce60786f2e51973add04011546aae3aedbd4964e5d025450e705aa9d3a513cf8c91
data/CHANGELOG.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  * Add config, reading from env vars and yml files (inspired by gem-release)
8
8
  * Add `abstract` in order to signal a cmd is a base class that is not meant to be executed
9
- * Add `required :one, [:two, :three]` (DNF, i.e: either :one or both :two and :three must be given)
9
+ * Add `required :one, [:two, :three]` (DNF, i.e: either `:one` or both `:two` and `:three` must be given)
10
10
  * Add `opt '--one STR', type: :array` for options that can be given multiple times
11
11
  * Add `opt '--one STR', default: 'one'`
12
12
  * Add `opt '--one STR', requires :two` or `[:two, :three]` for options that depend on other options
data/NOTES.md CHANGED
@@ -4,4 +4,6 @@
4
4
 
5
5
  - refactor Help::Cmd and Table so that everything goes into one big table
6
6
 
7
- - wrap long lines in help output
7
+ - add args descriptions
8
+
9
+
data/README.md CHANGED
@@ -1,22 +1,58 @@
1
1
  # CL [![Build Status](https://travis-ci.org/svenfuchs/cl.svg?branch=master)](https://travis-ci.org/svenfuchs/cl)
2
2
 
3
- This library wraps Ruby's `OptionParser` in order to make it easier to use it in an object oriented context.
3
+ This library wraps Ruby's `OptionParser` in order to make it easier to use it
4
+ in an object oriented context.
4
5
 
5
- ## Usage
6
+ It uses `OptionParser` for parsing your options, so you get all the goodness that
7
+ this true gem from Ruby's stoneage provides. But on top of that it also provides
8
+ a rich DSL for defining, validating, and normalizing options, and automatic and
9
+ gorgeous help output (modelled after Rubygem's `gem --help` output).
10
+
11
+ ## Basic Usage
6
12
 
7
13
  ```ruby
8
14
  module Owners
9
- class Add < Cli::Cmd
15
+ class Add < Cl::Cmd
16
+ summary 'Add one or more owners to an existing owner group'
10
17
 
11
- register 'owners:add'
18
+ description <<~str
19
+ Use this command to add one or more owners to an existing
20
+ owner group.
12
21
 
13
- purpose 'Add one or more owners to an existing owner group'
22
+ These will be visible in [...]
23
+ str
14
24
 
15
25
  args :owners
16
26
 
17
- opt '-t', '--to TO', 'An owner in an existing group' do |value|
27
+ opt '-t', '--to TO', 'An existing owner group' do |value|
18
28
  opts[:to] = value
19
29
  end
20
30
  end
21
31
  end
22
32
  ```
33
+
34
+ Help output:
35
+
36
+ ```txt
37
+ Usage: owners add [owners] [options]
38
+
39
+ Arguments:
40
+
41
+ owners type: string
42
+
43
+ Options:
44
+
45
+ -t --to TO An existing owner group (type: string, required: true)
46
+ --help Get help on this command (type: flag)
47
+
48
+ Summary:
49
+
50
+ Add one or more owners to an existing owner group
51
+
52
+ Description:
53
+
54
+ Use this command to add one or more owners to an existing
55
+ owner group.
56
+
57
+ These will be visible in [...]
58
+ ```
data/examples/owners ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ # Example from the README
5
+
6
+ require 'cl'
7
+
8
+ module Owners
9
+ class Add < Cl::Cmd
10
+
11
+ register 'owners:add'
12
+
13
+ summary 'Add one or more owners to an existing owner group'
14
+
15
+ description <<~str
16
+ Use this command to add one or more owners to an existing
17
+ owner group.
18
+
19
+ These will be visible in [...]
20
+ str
21
+
22
+ args :owners #, 'Comma separated list of owner login names who are to be added to the owner group'
23
+
24
+ opt '-t', '--to TO', 'An existing owner group', required: true
25
+ end
26
+ end
27
+
28
+ Cl.new($0).run(%w(add --help))
data/lib/cl/help/cmd.rb CHANGED
@@ -4,6 +4,8 @@ require 'cl/help/usage'
4
4
  class Cl
5
5
  class Help
6
6
  class Cmd
7
+ include Regex
8
+
7
9
  attr_reader :cmd
8
10
 
9
11
  def initialize(cmd)
@@ -100,7 +102,7 @@ class Cl
100
102
  opts << "alias: #{format_aliases(opt)}" if opt.aliases?
101
103
  opts << "requires: #{opt.requires.join(', ')}" if opt.requires?
102
104
  opts << "default: #{format_default(opt)}" if opt.default?
103
- opts << "known values: #{opt.enum.join(', ')}" if opt.enum?
105
+ opts << "known values: #{format_enum(opt)}" if opt.enum?
104
106
  opts << "format: #{opt.format}" if opt.format?
105
107
  opts << "downcase: true" if opt.downcase?
106
108
  opts << "max: #{opt.max}" if opt.max?
@@ -118,6 +120,9 @@ class Cl
118
120
  end.join(', ')
119
121
  end
120
122
 
123
+ def format_enum(opt)
124
+ opt.enum.map { |value| format_regex(value) }.join(', ')
125
+ end
121
126
 
122
127
  def format_type(obj)
123
128
  return obj.type unless obj.is_a?(Opt) && obj.type == :array
data/lib/cl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Cl
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-12 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: regstry
@@ -42,6 +42,7 @@ files:
42
42
  - examples/args/splat
43
43
  - examples/gem
44
44
  - examples/heroku
45
+ - examples/owners
45
46
  - examples/rakeish
46
47
  - lib/cl.rb
47
48
  - lib/cl/arg.rb