command_kit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +15 -0
  3. data/.rubocop.yml +138 -0
  4. data/ChangeLog.md +29 -0
  5. data/Gemfile +3 -0
  6. data/README.md +141 -121
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +7 -0
  11. data/lib/command_kit/arguments.rb +1 -1
  12. data/lib/command_kit/colors.rb +221 -45
  13. data/lib/command_kit/command.rb +1 -1
  14. data/lib/command_kit/commands.rb +4 -4
  15. data/lib/command_kit/help/man.rb +4 -25
  16. data/lib/command_kit/inflector.rb +47 -17
  17. data/lib/command_kit/main.rb +7 -9
  18. data/lib/command_kit/man.rb +44 -0
  19. data/lib/command_kit/open_app.rb +69 -0
  20. data/lib/command_kit/options/option.rb +1 -6
  21. data/lib/command_kit/options/parser.rb +15 -17
  22. data/lib/command_kit/options.rb +2 -2
  23. data/lib/command_kit/os/linux.rb +157 -0
  24. data/lib/command_kit/os.rb +159 -11
  25. data/lib/command_kit/package_manager.rb +200 -0
  26. data/lib/command_kit/pager.rb +46 -4
  27. data/lib/command_kit/printing/indent.rb +2 -2
  28. data/lib/command_kit/printing.rb +1 -1
  29. data/lib/command_kit/sudo.rb +40 -0
  30. data/lib/command_kit/terminal.rb +5 -0
  31. data/lib/command_kit/version.rb +1 -1
  32. data/spec/arguments/argument_spec.rb +1 -1
  33. data/spec/colors_spec.rb +256 -0
  34. data/spec/commands_spec.rb +1 -1
  35. data/spec/exception_handler_spec.rb +1 -1
  36. data/spec/help/man_spec.rb +0 -32
  37. data/spec/inflector_spec.rb +70 -8
  38. data/spec/man_spec.rb +46 -0
  39. data/spec/open_app_spec.rb +85 -0
  40. data/spec/options/option_spec.rb +2 -2
  41. data/spec/os/linux_spec.rb +154 -0
  42. data/spec/os_spec.rb +200 -13
  43. data/spec/package_manager_spec.rb +806 -0
  44. data/spec/pager_spec.rb +71 -6
  45. data/spec/sudo_spec.rb +51 -0
  46. data/spec/terminal_spec.rb +30 -0
  47. data/spec/usage_spec.rb +1 -1
  48. metadata +19 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acf8c9763694ffe7ac298e158863a3165c5d8f1a2209d1cac5b01e9c60d9dd85
4
- data.tar.gz: 98669568909de27878be028ae8b0251ddc6e8a4740af23037bd234d06778b2ce
3
+ metadata.gz: 5dc00be598fd9cee093dbfaf32a03118897179587d4dc17c97fdde2b020d3ac7
4
+ data.tar.gz: 88e498fa844b4db50dc194f6ec474d7c85bbea1619bf1340e6d2abfc4c13c0b3
5
5
  SHA512:
6
- metadata.gz: b04269a04b5d474f2a17724e04fa015fe5c1eefdbba9f53cf06c49c727c369ae3ba9a77e336c09f69fc3e7c8b6e5f77fa98abe7912c022213489d5b04191f5bb
7
- data.tar.gz: 01c43327289df1e30970e618b2d133e26bc5e6cdd3d65cc6fad7cbc369e44085fd164cb0b93a241df6508e3019fbfed658f83191e958457ec6f7ecfed86b88b3
6
+ metadata.gz: 5fd2683d7d3fb3f4c1258019d209b9f8ca348b0fc71c21c9f292b6799502dcfbc39d8f5ff8e50d54b822aaf229eedd85c3e151bea0f9c92d13dc08bb5b6d947e
7
+ data.tar.gz: 4276756c0495b2583303c9db090cd0e1221681d7eb357b34d4078a7e59167695f3250552c58ff0be24ee27535fb49ab2ce15d8e0711ee44cebbb93a52f6dfac0
@@ -3,6 +3,7 @@ name: CI
3
3
  on: [ push, pull_request ]
4
4
 
5
5
  jobs:
6
+ # run tests
6
7
  tests:
7
8
  runs-on: ubuntu-latest
8
9
  strategy:
@@ -27,3 +28,17 @@ jobs:
27
28
  run: bundle install --jobs 4 --retry 3
28
29
  - name: Run tests
29
30
  run: bundle exec rake test
31
+
32
+ # rubocop linting
33
+ rubocop:
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - uses: actions/checkout@v2
37
+ - name: Set up Ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: 2.7
41
+ - name: Install dependencies
42
+ run: bundle install --jobs 4 --retry 3
43
+ - name: Run rubocop
44
+ run: bundle exec rubocop --parallel
data/.rubocop.yml ADDED
@@ -0,0 +1,138 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 2.7
5
+
6
+ #
7
+ # our rules
8
+ #
9
+
10
+ Layout/FirstArrayElementIndentation: { EnforcedStyle: consistent }
11
+ Layout/LineLength: { Enabled: false }
12
+ Layout/SpaceAroundEqualsInParameterDefault: { EnforcedStyle: no_space }
13
+ Lint/ConstantDefinitionInBlock: { Exclude: ['spec/**/*'] }
14
+ Metrics: { Enabled: false }
15
+ Style/SymbolArray: { EnforcedStyle: brackets }
16
+ Style/IfInsideElse: { Enabled: false } # Offense count: 1
17
+ Style/PercentLiteralDelimiters:
18
+ Enabled: true
19
+ PreferredDelimiters:
20
+ default: '{}'
21
+ '%i': '[]'
22
+ '%I': '[]'
23
+ '%w': '[]'
24
+ '%W': '[]'
25
+
26
+ #
27
+ # rules that are in flux
28
+ #
29
+
30
+ # consider enabling these and autocorrecting?
31
+ # Layout/SpaceAfterComma
32
+ # Layout/SpaceAroundKeyword
33
+ # Layout/SpaceBeforeComma
34
+ # Layout/SpaceInsideHashLiteralBraces
35
+ # Layout/SpaceInsideParens
36
+ # Layout/TrailingWhitespace
37
+ # Lint/UnreachableLoop
38
+ # Lint/UnusedBlockArgument
39
+ # Style/ClassCheck
40
+ # Style/Documentation
41
+ # Style/ExpandPathArguments
42
+ # Style/GlobalStdStream
43
+ # Style/HashSyntax
44
+ # Style/KeywordParametersOrder
45
+ # Style/MethodCallWithoutArgsParentheses
46
+ # Style/MutableConstant
47
+ # Style/QuotedSymbols: { EnforcedStyle: double_quotes }
48
+ # Style/RedundantReturn
49
+ # Style/SafeNavigation
50
+ # Style/SpecialGlobalVars
51
+ # Style/StringLiterals: { EnforcedStyle: double_quotes }
52
+ # Style/WordArray
53
+
54
+ # these have been fixed
55
+ # Gemspec/DuplicatedAssignment: { Enabled: false } # Offense count: 1
56
+ # Layout/ElseAlignment: { Enabled: false } # Offense count: 1
57
+ # Layout/EndAlignment: { Enabled: false } # Offense count: 1
58
+ # Lint/DuplicateMethods: { Enabled: false } # Offense count: 1
59
+ # Lint/UselessAssignment: { Enabled: false } # Offense count: 1
60
+ # Style/Encoding: { Enabled: false } # Offense count: 2
61
+ # Style/RedundantBegin: { Enabled: false } # Offense count: 2
62
+ # Style/RedundantInterpolation: { Enabled: false } # Offense count: 1
63
+ # Style/TrailingCommaInArrayLiteral: { Enabled: false } # Offense count: 1
64
+
65
+ #
66
+ # This list was generated with:
67
+ # bundle exec rubocop --auto-gen-config --exclude-limit 1
68
+ #
69
+
70
+ # > 10 violations
71
+ Layout/AssignmentIndentation: { Enabled: false } # Offense count: 11
72
+ Layout/EmptyLinesAroundClassBody: { Enabled: false } # Offense count: 76
73
+ Layout/HashAlignment: { Enabled: false } # Offense count: 28
74
+ Layout/SpaceAfterComma: { Enabled: false } # Offense count: 141
75
+ Layout/SpaceInsideHashLiteralBraces: { Enabled: false } # Offense count: 57
76
+ Layout/TrailingWhitespace: { Enabled: false } # Offense count: 50
77
+ Naming/RescuedExceptionsVariableName: { Enabled: false } # Offense count: 11
78
+ Style/BlockDelimiters: { Enabled: false } # Offense count: 17
79
+ Style/ClassCheck: { Enabled: false } # Offense count: 10
80
+ Style/ClassEqualityComparison: { Enabled: false } # Offense count: 16
81
+ Style/FrozenStringLiteralComment: { Enabled: false } # Offense count: 77
82
+ Style/GlobalStdStream: { Enabled: false } # Offense count: 13
83
+ Style/GuardClause: { Enabled: false } # Offense count: 10
84
+ Style/IfUnlessModifier: { Enabled: false } # Offense count: 13
85
+ Style/MethodCallWithoutArgsParentheses: { Enabled: false } # Offense count: 10
86
+ Style/SpecialGlobalVars: { Enabled: false } # Offense count: 28
87
+ Style/StringLiterals: { Enabled: false } # Offense count: 774
88
+
89
+ # < 10 violations
90
+ Layout/EmptyLinesAroundModuleBody: { Enabled: false } # Offense count: 5
91
+ Layout/ExtraSpacing: { Enabled: false } # Offense count: 6
92
+ Layout/FirstHashElementIndentation: { Enabled: false } # Offense count: 4
93
+ Layout/ParameterAlignment: { Enabled: false } # Offense count: 9
94
+ Layout/SpaceAroundKeyword: { Enabled: false } # Offense count: 7
95
+ Layout/SpaceBeforeComma: { Enabled: false } # Offense count: 4
96
+ Layout/SpaceInsideParens: { Enabled: false } # Offense count: 4
97
+ Lint/EmptyClass: { Enabled: false } # Offense count: 3
98
+ Lint/SuppressedException: { Enabled: false } # Offense count: 4
99
+ Lint/UnusedMethodArgument: { Enabled: false } # Offense count: 5
100
+ Style/AccessorGrouping: { Enabled: false } # Offense count: 7
101
+ Style/Documentation: { Enabled: false } # Offense count: 3
102
+ Style/ExpandPathArguments: { Enabled: false } # Offense count: 8
103
+ Style/HashSyntax: { Exclude: ['Rakefile'] } # Offense count: 3
104
+ Style/KeywordParametersOrder: { Enabled: false } # Offense count: 8
105
+ Style/Lambda: { Enabled: false } # Offense count: 3
106
+ Style/MutableConstant: { Enabled: false } # Offense count: 4
107
+ Style/RaiseArgs: { Enabled: false } # Offense count: 4
108
+ Style/RedundantReturn: { Enabled: false } # Offense count: 7
109
+ Style/SafeNavigation: { Enabled: false } # Offense count: 5
110
+ Style/StringConcatenation: { Enabled: false } # Offense count: 8
111
+ Style/WordArray: { Enabled: false } # Offense count: 4
112
+
113
+ # 1 or 2 violations
114
+ Layout/ArgumentAlignment: { Enabled: false } # Offense count: 1
115
+ Layout/BlockAlignment: { Enabled: false } # Offense count: 1
116
+ Layout/IndentationWidth: { Enabled: false } # Offense count: 2
117
+ Layout/SpaceAroundOperators: { Enabled: false } # Offense count: 1
118
+ Layout/SpaceBeforeBlockBraces: { Enabled: false } # Offense count: 1
119
+ Lint/MissingSuper: { Enabled: false } # Offense count: 2
120
+ Lint/RescueException: { Enabled: false } # Offense count: 1
121
+ Lint/UnreachableLoop: { Enabled: false } # Offense count: 1
122
+ Lint/UnusedBlockArgument: { Enabled: false } # Offense count: 1
123
+ Naming/MethodParameterName: { Enabled: false } # Offense count: 1
124
+ Style/EmptyMethod: { Enabled: false } # Offense count: 2
125
+ Style/HashConversion: { Enabled: false } # Offense count: 1
126
+ Style/MultilineMemoization: { Enabled: false } # Offense count: 1
127
+ Style/NumericPredicate: { Enabled: false } # Offense count: 1
128
+ Style/OptionalArguments: { Enabled: false } # Offense count: 1
129
+ Style/ParenthesesAroundCondition: { Enabled: false } # Offense count: 1
130
+ Style/PreferredHashMethods: { Enabled: false } # Offense count: 1
131
+ Style/QuotedSymbols: { Enabled: false } # Offense count: 1
132
+ Style/RedundantException: { Enabled: false } # Offense count: 1
133
+ Style/RedundantRegexpEscape: { Enabled: false } # Offense count: 1
134
+ Style/RegexpLiteral: { Enabled: false } # Offense count: 1
135
+ Style/RescueStandardError: { Enabled: false } # Offense count: 1
136
+ Style/SoleNestedConditional: { Enabled: false } # Offense count: 1
137
+ Style/TrailingCommaInHashLiteral: { Enabled: false } # Offense count: 2
138
+ Style/PercentLiteralDelimiters: { Enabled: false } # Offense count: 2
data/ChangeLog.md CHANGED
@@ -1,3 +1,31 @@
1
+ ### 0.2.0 / 2021-08-31
2
+
3
+ * Added {CommandKit::Colors::ANSI#on_black}.
4
+ * Added {CommandKit::Colors::ANSI#on_red}.
5
+ * Added {CommandKit::Colors::ANSI#on_green}.
6
+ * Added {CommandKit::Colors::ANSI#on_yellow}.
7
+ * Added {CommandKit::Colors::ANSI#on_blue}.
8
+ * Added {CommandKit::Colors::ANSI#on_magenta}.
9
+ * Added {CommandKit::Colors::ANSI#on_cyan}.
10
+ * Added {CommandKit::Colors::ANSI#on_white}.
11
+ * Added {CommandKit::Man}.
12
+ * Added {CommandKit::OS#bsd?}.
13
+ * Added {CommandKit::OS#freebsd?}.
14
+ * Added {CommandKit::OS#netbsd?}.
15
+ * Added {CommandKit::OS#openbsd?}.
16
+ * Added {CommandKit::OS#os}.
17
+ * Added {CommandKit::OS#unix?}.
18
+ * Added {CommandKit::OS::Linux}.
19
+ * Added {CommandKit::OpenApp}.
20
+ * Added {CommandKit::PackageManager}.
21
+ * Added {CommandKit::Pager#pipe_to_pager}.
22
+ * Added {CommandKit::Sudo}.
23
+ * Added {CommandKit::Terminal#tty?}.
24
+ * Refactor {CommandKit::Inflector.camelize} and
25
+ {CommandKit::Inflector.underscore} to use StringScanner.
26
+ * Allow {CommandKit::OS#initialize} to accept an `os:` keyword to override the
27
+ detected OS.
28
+
1
29
  ### 0.1.0 / 2021-07-16
2
30
 
3
31
  * Initial release:
@@ -21,6 +49,7 @@
21
49
  * {CommandKit::Options}
22
50
  * {CommandKit::Options::Quiet}
23
51
  * {CommandKit::Options::Verbose}
52
+ * {CommandKit::OS}
24
53
  * {CommandKit::Pager}
25
54
  * {CommandKit::Printing}
26
55
  * {CommandKit::Printing::Indent}
data/Gemfile CHANGED
@@ -6,9 +6,12 @@ group :development do
6
6
  gem 'rake'
7
7
  gem 'rubygems-tasks', '~> 0.2'
8
8
 
9
+ gem 'rubocop', '~> 1.18'
10
+
9
11
  gem 'rspec', '~> 3.0'
10
12
  gem 'simplecov', '~> 0.20', require: false
11
13
 
12
14
  gem 'kramdown'
13
15
  gem 'yard', '~> 0.9'
16
+ gem 'yard-spellcheck', require: false
14
17
  end
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # command_kit
2
2
 
3
+ [![Build Status](https://github.com/postmodern/command_kit.rb/workflows/CI/badge.svg?branch=main)](https://github.com/postmodern/command_kit.rb/actions)
4
+
3
5
  * [Homepage](https://github.com/postmodern/command_kit.rb#readme)
4
- * [Forum](https://github.com/postmodern/command_kit.rb/discussions)
5
- * [Issues](https://github.com/postmodern/command_kit.rb/issues)
6
+ * [Forum](https://github.com/postmodern/command_kit.rb/discussions) |
7
+ [Issues](https://github.com/postmodern/command_kit.rb/issues)
6
8
  * [Documentation](http://rubydoc.info/gems/command_kit/frames)
7
9
 
8
10
  ## Description
@@ -12,53 +14,26 @@ plain-old Ruby classes.
12
14
 
13
15
  ## Features
14
16
 
15
- * Supports defining commands as Classes.
16
- * Supports defining options and arguments as attributes.
17
- * Supports extending commands via inheritance.
18
- * Supports subcommands (explicit or lazy-loaded) and command aliases.
19
- * Correctly handles Ctrl^C and SIGINT interrupts (aka exit 130).
20
- * Correctly handles broken pipes (aka `mycmd | head`).
21
- * Correctly handles when stdout or stdin is redirected to a file.
22
- * Uses [OptionParser][optparse] for POSIX option parsing.
23
- * Supports optionally displaying a man-page instead of `--help`
24
- (see {CommandKit::Help::Man}).
25
- * Supports optional ANSI coloring.
26
- * Supports interactively prompting for user input.
27
- * Supports easily detecting the terminal size.
28
- * Supports paging output with `less` or `more`.
29
- * Supports XDG directories (`~/.config/`, `~/.local/share/`, `~/.cache/`).
30
- * Easy to test (ex: `MyCmd.main(arg1, arg2, options: {foo: foo}) # => 0`)
31
-
32
- ### API
33
-
34
- * [CommandKit::Arguments](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Arguments)
35
- * [CommandKit::Colors](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Colors)
36
- * [CommandKit::Command](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Command)
37
- * [CommandKit::CommandName](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/CommandName)
38
- * [CommandKit::Commands](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Commands)
39
- * [CommandKit::Commands::AutoLoad](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Commands/AutoLoad)
40
- * [CommandKit::Commands::AutoRequire](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Commands/AutoRequire)
41
- * [CommandKit::Description](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Description)
42
- * [CommandKit::Env](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Env)
43
- * [CommandKit::Env::Home](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Env/Home)
44
- * [CommandKit::Env::Path](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Env/Path)
45
- * [CommandKit::Examples](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Examples)
46
- * [CommandKit::ExceptionHandler](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/ExceptionHandler)
47
- * [CommandKit::Help](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Help)
48
- * [CommandKit::Help::Man](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Help/Man)
49
- * [CommandKit::Interactive](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Interactive)
50
- * [CommandKit::Main](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Main)
51
- * [CommandKit::Options](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Options)
52
- * [CommandKit::Options::Quiet](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Options/Quiet)
53
- * [CommandKit::Options::Verbose](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Options/Verbose)
54
- * [CommandKit::Pager](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Pager)
55
- * [CommandKit::Printing](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Printing)
56
- * [CommandKit::Printing::Indent](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Printing/Indent)
57
- * [CommandKit::ProgramName](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/ProgramName)
58
- * [CommandKit::Stdio](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Stdio)
59
- * [CommandKit::Terminal](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Terminal)
60
- * [CommandKit::Usage](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/Usage)
61
- * [CommandKit::XDG](https://rubydoc.info/github/postmodern/command_kit/main/CommandKit/XDG)
17
+ * **Simple** - Commands are plain-old ruby classes, with options and
18
+ arguments declared as attributes. All features are ruby modules that can be
19
+ included into command classes.
20
+ * **Correct** - CommandKit behaves like a standard UNIX command.
21
+ * Safely handles Ctrl^C / SIGINT interrupts and [exits with 130](https://tldp.org/LDP/abs/html/exitcodes.html).
22
+ * Safely handles broken pipes (aka `mycmd | head`).
23
+ * Respects common environment variables (ex: `TERM=dumb`).
24
+ * Uses [OptionParser][optparse] for POSIX option parsing.
25
+ * Disables ANSI color when output is redirected to a file.
26
+ * **Complete** - Provides many additional CLI features.
27
+ * OS detection.
28
+ * Terminal size detection.
29
+ * ANSI coloring support.
30
+ * Interactive input.
31
+ * Subcommands (explicit or lazy-loaded) and command aliases.
32
+ * Displaying man pages for `--help`/`help`.
33
+ * Using the pager (aka `less`).
34
+ * [XDG directories](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) (aka `~/.config/`, `~/.local/share/`, `~/.cache/`).
35
+ * **Testable** - Since commands are plain-old ruby classes, it's easy to
36
+ initialize them and call `#main` or `#run`.
62
37
 
63
38
  ## Anti-Features
64
39
 
@@ -66,103 +41,148 @@ plain-old Ruby classes.
66
41
  * Does not implement it's own option parser.
67
42
  * Not named after a comic-book Superhero.
68
43
 
44
+ ## Requirements
45
+
46
+ * [ruby] >= 2.7.0
47
+
48
+ ## Install
49
+
50
+ ```sh
51
+ $ gem install command_kit
52
+ ```
53
+
54
+ ### gemspec
55
+
56
+ ```ruby
57
+ gem.add_dependency 'command_kit', '~> 0.2'
58
+ ```
59
+
60
+ ### Gemfile
61
+
62
+ ```ruby
63
+ gem 'command_kit', '~> 0.2'
64
+ ```
65
+
69
66
  ## Examples
70
67
 
71
68
  ### lib/foo/cli/my_cmd.rb
72
69
 
73
- require 'command_kit'
74
-
75
- module Foo
76
- module CLI
77
- class MyCmd < CommandKit::Command
78
-
79
- usage '[OPTIONS] [-o OUTPUT] FILE'
80
-
81
- option :count, short: '-c',
82
- value: {
83
- type: Integer,
84
- default: 1
85
- },
86
- desc: "Number of times"
87
-
88
- option :output, short: '-o',
89
- value: {
90
- type: String,
91
- usage: 'FILE'
92
- },
93
- desc: "Optional output file"
94
-
95
- option :verbose, short: '-v', desc: "Increase verbose level" do
96
- @verbose += 1
97
- end
98
-
99
- argument :file, required: true,
100
- usage: 'FILE',
101
- desc: "Input file"
102
-
103
- examples [
104
- '-o path/to/output.txt path/to/input.txt',
105
- '-v -c 2 -o path/to/output.txt path/to/input.txt',
106
- ]
107
-
108
- description 'Example command'
109
-
110
- def initialize(**kwargs)
111
- super(**kwargs)
112
-
113
- @verbose = 0
114
- end
115
-
116
- def run(file)
117
- puts "count=#{options[:count].inspect}"
118
- puts "output=#{options[:output].inspect}"
119
- puts "file=#{file.inspect}"
120
- puts "verbose=#{@verbose.inspect}"
121
- end
122
-
123
- end
70
+ ```ruby
71
+ require 'command_kit'
72
+
73
+ module Foo
74
+ module CLI
75
+ class MyCmd < CommandKit::Command
76
+
77
+ usage '[OPTIONS] [-o OUTPUT] FILE'
78
+
79
+ option :count, short: '-c',
80
+ value: {
81
+ type: Integer,
82
+ default: 1
83
+ },
84
+ desc: "Number of times"
85
+
86
+ option :output, short: '-o',
87
+ value: {
88
+ type: String,
89
+ usage: 'FILE'
90
+ },
91
+ desc: "Optional output file"
92
+
93
+ option :verbose, short: '-v', desc: "Increase verbose level" do
94
+ @verbose += 1
95
+ end
96
+
97
+ argument :file, required: true,
98
+ usage: 'FILE',
99
+ desc: "Input file"
100
+
101
+ examples [
102
+ '-o path/to/output.txt path/to/input.txt',
103
+ '-v -c 2 -o path/to/output.txt path/to/input.txt',
104
+ ]
105
+
106
+ description 'Example command'
107
+
108
+ def initialize(**kwargs)
109
+ super(**kwargs)
110
+
111
+ @verbose = 0
124
112
  end
113
+
114
+ def run(file)
115
+ puts "count=#{options[:count].inspect}"
116
+ puts "output=#{options[:output].inspect}"
117
+ puts "file=#{file.inspect}"
118
+ puts "verbose=#{@verbose.inspect}"
119
+ end
120
+
125
121
  end
122
+ end
123
+ end
124
+ ```
126
125
 
127
126
  ### bin/my_cmd
128
127
 
129
- #!/usr/bin/env ruby
130
-
131
- $LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
132
- require 'foo/cli/my_cmd'
133
-
134
- Foo::CLI::MyCmd.start
128
+ ```ruby
129
+ #!/usr/bin/env ruby
130
+
131
+ $LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
132
+ require 'foo/cli/my_cmd'
133
+
134
+ Foo::CLI::MyCmd.start
135
+ ```
135
136
 
136
137
  ### --help
137
138
 
138
139
  Usage: my_cmd [OPTIONS] [-o OUTPUT] FILE
139
-
140
+
140
141
  Options:
141
142
  -c, --count INT Number of times (Default: 1)
142
143
  -o, --output FILE Optional output file
143
144
  -v, --verbose Increase verbose level
144
145
  -h, --help Print help information
145
-
146
+
146
147
  Arguments:
147
148
  FILE Input file
148
-
149
+
149
150
  Examples:
150
151
  my_cmd -o path/to/output.txt path/to/input.txt
151
152
  my_cmd -v -c 2 -o path/to/output.txt path/to/input.txt
152
-
153
- Example command
154
-
155
- ## Requirements
156
-
157
- * [ruby] >= 2.7.0
158
153
 
159
- ## Install
160
-
161
- $ gem install command_kit
162
-
163
- ### Gemfile
154
+ Example command
164
155
 
165
- gem 'command_kit', '~> 0.1'
156
+ ### Reference
157
+
158
+ * [CommandKit::Arguments](https://rubydoc.info/gems/command_kit/CommandKit/Arguments)
159
+ * [CommandKit::Colors](https://rubydoc.info/gems/command_kit/CommandKit/Colors)
160
+ * [CommandKit::Command](https://rubydoc.info/gems/command_kit/CommandKit/Command)
161
+ * [CommandKit::CommandName](https://rubydoc.info/gems/command_kit/CommandKit/CommandName)
162
+ * [CommandKit::Commands](https://rubydoc.info/gems/command_kit/CommandKit/Commands)
163
+ * [CommandKit::Commands::AutoLoad](https://rubydoc.info/gems/command_kit/CommandKit/Commands/AutoLoad)
164
+ * [CommandKit::Commands::AutoRequire](https://rubydoc.info/gems/command_kit/CommandKit/Commands/AutoRequire)
165
+ * [CommandKit::Description](https://rubydoc.info/gems/command_kit/CommandKit/Description)
166
+ * [CommandKit::Env](https://rubydoc.info/gems/command_kit/CommandKit/Env)
167
+ * [CommandKit::Env::Home](https://rubydoc.info/gems/command_kit/CommandKit/Env/Home)
168
+ * [CommandKit::Env::Path](https://rubydoc.info/gems/command_kit/CommandKit/Env/Path)
169
+ * [CommandKit::Examples](https://rubydoc.info/gems/command_kit/CommandKit/Examples)
170
+ * [CommandKit::ExceptionHandler](https://rubydoc.info/gems/command_kit/CommandKit/ExceptionHandler)
171
+ * [CommandKit::Help](https://rubydoc.info/gems/command_kit/CommandKit/Help)
172
+ * [CommandKit::Help::Man](https://rubydoc.info/gems/command_kit/CommandKit/Help/Man)
173
+ * [CommandKit::Interactive](https://rubydoc.info/gems/command_kit/CommandKit/Interactive)
174
+ * [CommandKit::Main](https://rubydoc.info/gems/command_kit/CommandKit/Main)
175
+ * [CommandKit::Options](https://rubydoc.info/gems/command_kit/CommandKit/Options)
176
+ * [CommandKit::Options::Quiet](https://rubydoc.info/gems/command_kit/CommandKit/Options/Quiet)
177
+ * [CommandKit::Options::Verbose](https://rubydoc.info/gems/command_kit/CommandKit/Options/Verbose)
178
+ * [CommandKit::Pager](https://rubydoc.info/gems/command_kit/CommandKit/Pager)
179
+ * [CommandKit::Printing](https://rubydoc.info/gems/command_kit/CommandKit/Printing)
180
+ * [CommandKit::Printing::Indent](https://rubydoc.info/gems/command_kit/CommandKit/Printing/Indent)
181
+ * [CommandKit::ProgramName](https://rubydoc.info/gems/command_kit/CommandKit/ProgramName)
182
+ * [CommandKit::Stdio](https://rubydoc.info/gems/command_kit/CommandKit/Stdio)
183
+ * [CommandKit::Terminal](https://rubydoc.info/gems/command_kit/CommandKit/Terminal)
184
+ * [CommandKit::Usage](https://rubydoc.info/gems/command_kit/CommandKit/Usage)
185
+ * [CommandKit::XDG](https://rubydoc.info/gems/command_kit/CommandKit/XDG)
166
186
 
167
187
  ## Alternatives
168
188