hanami-cli 0.2.0 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.gitignore +4 -2
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +25 -1
  6. data/CHANGELOG.md +39 -1
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +13 -6
  9. data/LICENSE.txt +21 -0
  10. data/README.md +13 -488
  11. data/Rakefile +8 -15
  12. data/bin/console +1 -0
  13. data/exe/hanami +10 -0
  14. data/hanami-cli.gemspec +24 -18
  15. data/lib/hanami/cli.rb +10 -121
  16. data/lib/hanami/cli/bundler.rb +73 -0
  17. data/lib/hanami/cli/command.rb +16 -355
  18. data/lib/hanami/cli/command_line.rb +17 -0
  19. data/lib/hanami/cli/commands.rb +26 -0
  20. data/lib/hanami/cli/commands/application.rb +63 -0
  21. data/lib/hanami/cli/commands/db/utils/database.rb +122 -0
  22. data/lib/hanami/cli/commands/db/utils/database_config.rb +48 -0
  23. data/lib/hanami/cli/commands/db/utils/mysql.rb +27 -0
  24. data/lib/hanami/cli/commands/db/utils/postgres.rb +49 -0
  25. data/lib/hanami/cli/commands/db/utils/sqlite.rb +37 -0
  26. data/lib/hanami/cli/commands/gem.rb +21 -0
  27. data/lib/hanami/cli/commands/gem/new.rb +77 -0
  28. data/lib/hanami/cli/commands/gem/version.rb +18 -0
  29. data/lib/hanami/cli/commands/monolith.rb +55 -0
  30. data/lib/hanami/cli/commands/monolith/console.rb +50 -0
  31. data/lib/hanami/cli/commands/monolith/db/create.rb +25 -0
  32. data/lib/hanami/cli/commands/monolith/db/create_migration.rb +29 -0
  33. data/lib/hanami/cli/commands/monolith/db/drop.rb +25 -0
  34. data/lib/hanami/cli/commands/monolith/db/migrate.rb +40 -0
  35. data/lib/hanami/cli/commands/monolith/db/reset.rb +26 -0
  36. data/lib/hanami/cli/commands/monolith/db/rollback.rb +55 -0
  37. data/lib/hanami/cli/commands/monolith/db/sample_data.rb +40 -0
  38. data/lib/hanami/cli/commands/monolith/db/seed.rb +40 -0
  39. data/lib/hanami/cli/commands/monolith/db/setup.rb +24 -0
  40. data/lib/hanami/cli/commands/monolith/db/structure/dump.rb +25 -0
  41. data/lib/hanami/cli/commands/monolith/db/version.rb +26 -0
  42. data/lib/hanami/cli/commands/monolith/generate.rb +14 -0
  43. data/lib/hanami/cli/commands/monolith/generate/action.rb +62 -0
  44. data/lib/hanami/cli/commands/monolith/generate/slice.rb +62 -0
  45. data/lib/hanami/cli/commands/monolith/install.rb +16 -0
  46. data/lib/hanami/cli/commands/monolith/version.rb +18 -0
  47. data/lib/hanami/cli/error.rb +8 -0
  48. data/lib/hanami/cli/generators/context.rb +38 -0
  49. data/lib/hanami/cli/generators/gem/application.rb +21 -0
  50. data/lib/hanami/cli/generators/gem/application/monolith.rb +83 -0
  51. data/lib/hanami/cli/generators/gem/application/monolith/action.erb +21 -0
  52. data/lib/hanami/cli/generators/gem/application/monolith/application.erb +8 -0
  53. data/lib/hanami/cli/generators/gem/application/monolith/config_ru.erb +5 -0
  54. data/lib/hanami/cli/generators/gem/application/monolith/entities.erb +9 -0
  55. data/lib/hanami/cli/generators/gem/application/monolith/env.erb +0 -0
  56. data/lib/hanami/cli/generators/gem/application/monolith/functions.erb +13 -0
  57. data/lib/hanami/cli/generators/gem/application/monolith/gemfile.erb +19 -0
  58. data/lib/hanami/cli/generators/gem/application/monolith/keep.erb +0 -0
  59. data/lib/hanami/cli/generators/gem/application/monolith/operation.erb +18 -0
  60. data/lib/hanami/cli/generators/gem/application/monolith/rakefile.erb +3 -0
  61. data/lib/hanami/cli/generators/gem/application/monolith/readme.erb +1 -0
  62. data/lib/hanami/cli/generators/gem/application/monolith/repository.erb +13 -0
  63. data/lib/hanami/cli/generators/gem/application/monolith/routes.erb +4 -0
  64. data/lib/hanami/cli/generators/gem/application/monolith/settings.erb +6 -0
  65. data/lib/hanami/cli/generators/gem/application/monolith/types.erb +10 -0
  66. data/lib/hanami/cli/generators/gem/application/monolith/validation_contract.erb +14 -0
  67. data/lib/hanami/cli/generators/gem/application/monolith/view_context.erb +15 -0
  68. data/lib/hanami/cli/generators/monolith/action.rb +123 -0
  69. data/lib/hanami/cli/generators/monolith/action/action.erb +13 -0
  70. data/lib/hanami/cli/generators/monolith/action/template.erb +0 -0
  71. data/lib/hanami/cli/generators/monolith/action/template.html.erb +2 -0
  72. data/lib/hanami/cli/generators/monolith/action/view.erb +13 -0
  73. data/lib/hanami/cli/generators/monolith/action_context.rb +76 -0
  74. data/lib/hanami/cli/generators/monolith/slice.rb +56 -0
  75. data/lib/hanami/cli/generators/monolith/slice/action.erb +9 -0
  76. data/lib/hanami/cli/generators/monolith/slice/entities.erb +9 -0
  77. data/lib/hanami/cli/generators/monolith/slice/keep.erb +0 -0
  78. data/lib/hanami/cli/generators/monolith/slice/repository.erb +10 -0
  79. data/lib/hanami/cli/generators/monolith/slice/routes.erb +2 -0
  80. data/lib/hanami/cli/generators/monolith/slice/view.erb +9 -0
  81. data/lib/hanami/cli/generators/monolith/slice_context.rb +33 -0
  82. data/lib/hanami/cli/repl/core.rb +55 -0
  83. data/lib/hanami/cli/repl/irb.rb +41 -0
  84. data/lib/hanami/cli/repl/pry.rb +29 -0
  85. data/lib/hanami/cli/system_call.rb +51 -0
  86. data/lib/hanami/cli/url.rb +34 -0
  87. data/lib/hanami/cli/version.rb +4 -3
  88. data/lib/hanami/console/context.rb +39 -0
  89. data/lib/hanami/console/plugins/slice_readers.rb +42 -0
  90. data/lib/hanami/rake_tasks.rb +52 -0
  91. metadata +138 -41
  92. data/.travis.yml +0 -16
  93. data/lib/hanami/cli/banner.rb +0 -126
  94. data/lib/hanami/cli/command_registry.rb +0 -213
  95. data/lib/hanami/cli/errors.rb +0 -32
  96. data/lib/hanami/cli/option.rb +0 -125
  97. data/lib/hanami/cli/parser.rb +0 -122
  98. data/lib/hanami/cli/program_name.rb +0 -19
  99. data/lib/hanami/cli/registry.rb +0 -328
  100. data/lib/hanami/cli/usage.rb +0 -88
  101. data/script/ci +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 044e34cdce8dfde02f57f2f3fbe10ea692b8461a22a0bdf0b68c1c52da00e7cb
4
- data.tar.gz: 918fae86bce89456402f4adf519b94368f2d715b873fa0ea00df4b8b561dc2d8
3
+ metadata.gz: 9de5812f665993e5c2ef2df77e3bee3f78c0917b3089f2bb822b0eab04e2d8e7
4
+ data.tar.gz: 1cc451a367b2ecd1959b30604808d99efb39a819bba9726e7f0f3ef0dc98dd6d
5
5
  SHA512:
6
- metadata.gz: 44baad40e044c7139753fab32c25ce821478888c01ac4a17626fe8be10797d80181a8915e135fd714f301e5b1deb9aca2cb154183f3fbca327eb5407230a36b1
7
- data.tar.gz: 4a2fe7be25963816e6970fa0ae3e6fdd6d0c030313303efa60ae76e88a90cb1c357809d13823f2a258bbd99bff2ce67b59449d311f332ee05cf5d301a32934b3
6
+ metadata.gz: 8ff9f2bf4104febfee8cdcd230fcd56b6bb54c18651cd0c1e8acfa58ebb216ec70060e7e4ea331b11bd56c67f8236b6f48ad212a514c28489a0cfa19acc5e761
7
+ data.tar.gz: 304bf695102705acb0fbc1f64729c6111ffd3aa464770854826c6554e2e8a48ed8b12028f353b123e05951570e871468f98db3b4547fe7440f20381503e551ca
@@ -0,0 +1,42 @@
1
+ name: ci
2
+
3
+ "on":
4
+ push:
5
+ paths:
6
+ - ".github/workflows/ci.yml"
7
+ - "lib/**"
8
+ - "*.gemspec"
9
+ - "spec/**"
10
+ - "Rakefile"
11
+ - "Gemfile"
12
+ - ".rubocop.yml"
13
+ pull_request:
14
+ branches:
15
+ - master
16
+ create:
17
+
18
+ jobs:
19
+ tests:
20
+ runs-on: ubuntu-latest
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ ruby:
25
+ - "3.0"
26
+ - "2.7"
27
+ - "2.6"
28
+ steps:
29
+ - uses: actions/checkout@v1
30
+ - name: Install package dependencies
31
+ run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
32
+ - name: Set up Ruby
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{matrix.ruby}}
36
+ - name: Install latest bundler
37
+ run: |
38
+ gem install bundler --no-document
39
+ - name: Bundle install
40
+ run: bundle install --jobs 4 --retry 3
41
+ - name: Run all tests
42
+ run: bundle exec rake spec
data/.gitignore CHANGED
@@ -1,11 +1,13 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
10
- .byebug_history
11
9
  .rubocop-*
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --format documentation
1
2
  --color
2
3
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,4 +1,28 @@
1
1
  # Please keep AllCops, Bundler, Style, Metrics groups and then order cops
2
2
  # alphabetically
3
+ AllCops:
4
+ SuggestExtensions: false
3
5
  inherit_from:
4
- - https://raw.githubusercontent.com/hanami/devtools/master/.rubocop.yml
6
+ - https://raw.githubusercontent.com/hanami/devtools/master/.rubocop-unstable.yml
7
+ Layout/LineLength:
8
+ Exclude:
9
+ - Gemfile
10
+ Naming/HeredocDelimiterNaming:
11
+ Enabled: false
12
+ Naming/MethodParameterName:
13
+ AllowedNames:
14
+ - fs
15
+ Style/AccessorGrouping:
16
+ Enabled: false
17
+ Style/BlockDelimiters:
18
+ Enabled: false
19
+ Style/CommentedKeyword:
20
+ Enabled: false
21
+ Style/LambdaCall:
22
+ Enabled: false
23
+ Style/TrailingCommaInArguments:
24
+ Enabled: false
25
+ Style/TrailingCommaInArrayLiteral:
26
+ Enabled: false
27
+ Style/TrailingCommaInHashLiteral:
28
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Hanami::CLI
2
- General purpose Command Line Interface (CLI) framework for Ruby
2
+ Hanami Command Line Interface
3
+
4
+ ## v2.0.0.alpha2 - 2021-05-04
5
+ ### Added
6
+ - [Luca Guidi] Official support for Ruby: MRI 3.0
7
+ - [Luca Guidi] Dynamically change the set of available commands depending on the context (outside or inside an Hanami app)
8
+ - [Luca Guidi] Dynamically change the set of available commands depending on Hanami app architecture
9
+ - [Luca Guidi] Implemented `hanami version` (available both outside and inside an Hanami app)
10
+ - [Piotr Solnica] Implemented `db *` commands (available both outside and inside an Hanami app) (sqlite and postgres only for now)
11
+ - [Piotr Solnica] Implemented `console` command with support for `IRB` and `Pry` (`pry` is auto-detected)
12
+
13
+ ### Changed
14
+ - [Luca Guidi] Changed the purpose of this gem: the CLI Ruby framework has been extracted into `dry-cli` gem. `hanami-cli` is now the `hanami` command line.
15
+ - [Luca Guidi] Drop support for Ruby: MRI 2.5.
16
+
17
+ ## v1.0.0.alpha1 - 2019-01-30
18
+ ### Added
19
+ - [Luca Guidi] Inheritng from subclasses of `Hanami::CLI::Command`, allows to inherit arguments, options, description, and examples.
20
+ - [Luca Guidi] Allow to use `super` from `#call`
21
+
22
+ ### Changed
23
+ - [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
24
+
25
+ ## v0.3.1 - 2019-01-18
26
+ ### Added
27
+ - [Luca Guidi] Official support for Ruby: MRI 2.6
28
+ - [Luca Guidi] Support `bundler` 2.0+
29
+
30
+ ## v0.3.0 - 2018-10-24
31
+
32
+ ## v0.3.0.beta1 - 2018-08-08
33
+ ### Added
34
+ - [Anton Davydov & Alfonso Uceda] Introduce array type for arguments (`foo exec test spec/bookshelf/entities spec/bookshelf/repositories`)
35
+ - [Anton Davydov & Alfonso Uceda] Introduce array type for options (`foo generate config --apps=web,api`)
36
+ - [Alfonso Uceda] Introduce variadic arguments (`foo run ruby:latest -- ruby -v`)
37
+ - [Luca Guidi] Official support for JRuby 9.2.0.0
38
+
39
+ ### Fixed
40
+ - [Anton Davydov] Print informative message when unknown or wrong option is passed (`"test" was called with arguments "--framework=unknown"`)
3
41
 
4
42
  ## v0.2.0 - 2018-04-11
5
43
 
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@lucaguidi.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile CHANGED
@@ -1,11 +1,18 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
  gemspec
3
5
 
4
- unless ENV['TRAVIS']
5
- gem 'byebug', require: false, platforms: :mri
6
- gem 'yard', require: false
6
+ unless ENV["CI"]
7
+ gem "byebug", require: false, platforms: :mri
8
+ gem "yard", require: false
7
9
  end
8
10
 
9
- gem 'hanami-utils', '~> 1.2', require: false, git: 'https://github.com/hanami/utils.git', branch: 'develop'
11
+ gem "hanami", require: false, git: "https://github.com/hanami/hanami.git", branch: "unstable"
12
+ gem "hanami-view", require: false, git: "https://github.com/hanami/view.git", branch: "unstable"
13
+
14
+ gem "rack"
10
15
 
11
- gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
16
+ group :test do
17
+ gem "pry"
18
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Luca Guidi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,223 +1,18 @@
1
1
  # Hanami::CLI
2
2
 
3
- General purpose Command Line Interface (CLI) framework for Ruby.
4
-
5
- :warning: **This is a general framework for Ruby (aka `thor` gem replacement), NOT the implementation of the `hanami` CLI commands** :warning:
6
-
7
- <!-- Tocer[start]: Auto-generated, don't remove. -->
8
-
9
- ## Table of Contents
10
-
11
- - [Features](#features)
12
- - [Registration](#registration)
13
- - [Commands as objects](#commands-as-objects)
14
- - [Subcommands](#subcommands)
15
- - [Arguments](#arguments)
16
- - [Option](#option)
17
- - [Installation](#installation)
18
- - [Usage](#usage)
19
- - [Available commands](#available-commands)
20
- - [Help](#help)
21
- - [Optional arguments](#optional-arguments)
22
- - [Required arguments](#required-arguments)
23
- - [Options](#options)
24
- - [Boolean options](#boolean-options)
25
- - [Subcommands](#subcommands-1)
26
- - [Aliases](#aliases)
27
- - [Subcommand aliases](#subcommand-aliases)
28
- - [Callbacks](#callbacks)
29
- - [Development](#development)
30
- - [Contributing](#contributing)
31
- - [Alternatives](#alternatives)
32
- - [Copyright](#copyright)
33
-
34
- <!-- Tocer[finish]: Auto-generated, don't remove. -->
35
-
36
- ## Features
37
-
38
- ### Registration
39
-
40
- For a given _command name_, you can register a corresponding _command object_ (aka command).
41
-
42
- Example: for `foo hi` _command name_ there is the corresponding `Foo::CLI::Hello` _command object_.
43
-
44
- ```ruby
45
- #!/usr/bin/env ruby
46
- require "bundler/setup"
47
- require "hanami/cli"
48
-
49
- module Foo
50
- module CLI
51
- module Commands
52
- extend Hanami::CLI::Registry
53
-
54
- class Hello < Hanami::CLI::Command
55
- def call(*)
56
- end
57
- end
58
- end
59
- end
60
- end
61
-
62
- class Version < Hanami::CLI::Command
63
- def call(*)
64
- end
65
- end
66
-
67
- Foo::CLI::Commands.register "hi", Foo::CLI::Commands::Hello
68
- Foo::CLI::Commands.register "v", Version
69
-
70
- Hanami::CLI.new(Foo::CLI::Commands).call
71
- ```
72
-
73
- **Please note:** there is NOT a convention between the _command name_ and the _command object_ class.
74
- The manual _registration_ assigns a _command object_ to a _command name_.
75
-
76
- ### Commands as objects
77
-
78
- A command is a subclass of `Hanami::CLI::Command` and it MUST respond to `#call(*)`.
79
-
80
- ### Subcommands
81
-
82
- There is nothing special in subcommands: they are just _command objects_ registered under a **nested** _command name_.
83
-
84
- ```ruby
85
- #!/usr/bin/env ruby
86
- require "bundler/setup"
87
- require "hanami/cli"
88
-
89
- module Foo
90
- module CLI
91
- module Commands
92
- extend Hanami::CLI::Registry
93
-
94
- module Generate
95
- class Configuration < Hanami::CLI::Command
96
- def call(*)
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
103
-
104
- Foo::CLI::Commands.register "generate configuration", Foo::CLI::Commands::Generate::Configuration
105
-
106
- Hanami::CLI.new(Foo::CLI::Commands).call
107
- ```
108
-
109
- ### Arguments
110
-
111
- An argument is a token passed after the _command name_.
112
- For instance, given the `foo greet` command, when an user types `foo greet Luca`, then `Luca` is considered an argument.
113
- A command can accept none or many arguments.
114
- An argument can be declared as _required_.
115
-
116
- ```ruby
117
- #!/usr/bin/env ruby
118
- require "bundler/setup"
119
- require "hanami/cli"
120
-
121
- module Foo
122
- module CLI
123
- module Commands
124
- extend Hanami::CLI::Registry
125
-
126
- class Greet < Hanami::CLI::Command
127
- argument :name, required: true, desc: "The name of the person to greet"
128
- argument :age, desc: "The age of the person to greet"
129
-
130
- def call(name:, age: nil, **)
131
- result = "Hello, #{name}."
132
- result = "#{result} You are #{age} years old." unless age.nil?
133
-
134
- puts result
135
- end
136
- end
137
-
138
- register "greet", Greet
139
- end
140
- end
141
- end
142
-
143
- Hanami::CLI.new(Foo::CLI::Commands).call
144
- ```
145
-
146
- ```shell
147
- % foo greet Luca
148
- Hello, Luca.
149
- ```
150
-
151
- ```shell
152
- % foo greet Luca 35
153
- Hello, Luca. You are 35 years old.
154
- ```
155
-
156
- ```shell
157
- % foo greet
158
- ERROR: "foo greet" was called with no arguments
159
- Usage: "foo greet NAME"
160
- ```
161
-
162
- ### Option
163
-
164
- An option is a named argument that is passed after the _command name_ **and** the arguments.
165
-
166
- For instance, given the `foo request` command, when an user types `foo request --mode=http2`, then `--mode=http2` is considered an option.
167
- A command can accept none or many options.
168
-
169
- ```ruby
170
- #!/usr/bin/env ruby
171
- require "bundler/setup"
172
- require "hanami/cli"
173
-
174
- module Foo
175
- module CLI
176
- module Commands
177
- extend Hanami::CLI::Registry
178
-
179
- class Request < Hanami::CLI::Command
180
- option :mode, default: "http", values: %w[http http2], desc: "The request mode"
181
-
182
- def call(**options)
183
- puts "Performing a request (mode: #{options.fetch(:mode)})"
184
- end
185
- end
186
-
187
- register "request", Request
188
- end
189
- end
190
- end
191
-
192
- Hanami::CLI.new(Foo::CLI::Commands).call
193
- ```
194
-
195
- ```shell
196
- % foo request
197
- Performing a request (mode: http)
198
- ```
199
-
200
- ```shell
201
- % foo request --mode=http2
202
- Performing a request (mode: http2)
203
- ```
204
-
205
- ```shell
206
- % foo request --mode=unknown
207
- Error: Invalid param provided
208
- ```
3
+ [Hanami](http://hanamirb.org) command line
209
4
 
210
5
  ## Installation
211
6
 
212
7
  Add this line to your application's Gemfile:
213
8
 
214
9
  ```ruby
215
- gem "hanami-cli"
10
+ gem 'hanami-cli'
216
11
  ```
217
12
 
218
13
  And then execute:
219
14
 
220
- $ bundle
15
+ $ bundle install
221
16
 
222
17
  Or install it yourself as:
223
18
 
@@ -225,294 +20,24 @@ Or install it yourself as:
225
20
 
226
21
  ## Usage
227
22
 
228
- Imagine to build a CLI executable `foo` for your Ruby project.
229
-
230
- ```ruby
231
- #!/usr/bin/env ruby
232
- require "bundler/setup"
233
- require "hanami/cli"
234
-
235
- module Foo
236
- module CLI
237
- module Commands
238
- extend Hanami::CLI::Registry
239
-
240
- class Version < Hanami::CLI::Command
241
- desc "Print version"
242
-
243
- def call(*)
244
- puts "1.0.0"
245
- end
246
- end
247
-
248
- class Echo < Hanami::CLI::Command
249
- desc "Print input"
250
-
251
- argument :input, desc: "Input to print"
252
-
253
- example [
254
- " # Prints 'wuh?'",
255
- "hello, folks # Prints 'hello, folks'"
256
- ]
257
-
258
- def call(input: nil, **)
259
- if input.nil?
260
- puts "wuh?"
261
- else
262
- puts input
263
- end
264
- end
265
- end
266
-
267
- class Start < Hanami::CLI::Command
268
- desc "Start Foo machinery"
269
-
270
- argument :root, required: true, desc: "Root directory"
271
-
272
- example [
273
- "path/to/root # Start Foo at root directory"
274
- ]
275
-
276
- def call(root:, **)
277
- puts "started - root: #{root}"
278
- end
279
- end
280
-
281
- class Stop < Hanami::CLI::Command
282
- desc "Stop Foo machinery"
283
-
284
- option :graceful, type: :boolean, default: true, desc: "Graceful stop"
285
-
286
- def call(**options)
287
- puts "stopped - graceful: #{options.fetch(:graceful)}"
288
- end
289
- end
290
-
291
- module Generate
292
- class Configuration < Hanami::CLI::Command
293
- desc "Generate configuration"
294
-
295
- def call(*)
296
- puts "generated configuration"
297
- end
298
- end
299
-
300
- class Test < Hanami::CLI::Command
301
- desc "Generate tests"
302
-
303
- option :framework, default: "minitest", values: %w[minitest rspec]
304
-
305
- def call(framework:, **)
306
- puts "generated tests - framework: #{framework}"
307
- end
308
- end
309
- end
310
-
311
- register "version", Version, aliases: ["v", "-v", "--version"]
312
- register "echo", Echo
313
- register "start", Start
314
- register "stop", Stop
315
-
316
- register "generate", aliases: ["g"] do |prefix|
317
- prefix.register "config", Generate::Configuration
318
- prefix.register "test", Generate::Test
319
- end
320
- end
321
- end
322
- end
323
-
324
- Hanami::CLI.new(Foo::CLI::Commands).call
325
- ```
326
-
327
- Let's have a look at the command line usage.
328
-
329
- ### Available commands
330
-
331
- ```shell
332
- % foo
333
- Commands:
334
- foo echo [INPUT] # Print input
335
- foo generate [SUBCOMMAND]
336
- foo start ROOT # Start Foo machinery
337
- foo stop # Stop Foo machinery
338
- foo version # Print version
339
- ```
340
-
341
- ### Help
342
-
343
- ```shell
344
- % foo echo --help
345
- Command:
346
- foo echo
347
-
348
- Usage:
349
- foo echo [INPUT]
350
-
351
- Description:
352
- Print input
353
-
354
- Arguments:
355
- INPUT # Input to print
356
-
357
- Options:
358
- --help, -h # Print this help
359
-
360
- Examples:
361
- foo echo # Prints 'wuh?'
362
- foo echo hello, folks # Prints 'hello, folks'
363
- ```
364
-
365
- ### Optional arguments
366
-
367
- ```shell
368
- % foo echo
369
- wuh?
370
-
371
- % foo echo hello
372
- hello
373
- ```
374
-
375
- ### Required arguments
376
-
377
- ```shell
378
- % foo start .
379
- started - root: .
380
- ```
381
-
382
- ```shell
383
- % foo start
384
- ERROR: "foo start" was called with no arguments
385
- Usage: "foo start ROOT"
386
- ```
387
-
388
- ### Options
389
-
390
- ```shell
391
- % foo generate test
392
- generated tests - framework: minitest
393
- ```
394
-
395
- ```shell
396
- % foo generate test --framework=rspec
397
- generated tests - framework: rspec
398
- ```
399
-
400
- ```shell
401
- % foo generate test --framework=unknown
402
- Error: Invalid param provided
403
- ```
404
-
405
- ### Boolean options
406
-
407
- ```shell
408
- % foo stop
409
- stopped - graceful: true
410
- ```
411
-
412
- ```shell
413
- % foo stop --no-graceful
414
- stopped - graceful: false
415
- ```
416
-
417
- ### Subcommands
418
-
419
- ```shell
420
- % foo generate
421
- Commands:
422
- foo generate config # Generate configuration
423
- foo generate test # Generate tests
424
- ```
425
-
426
- ### Aliases
427
-
428
- ```shell
429
- % foo version
430
- 1.0.0
431
- ```
432
-
433
- ```shell
434
- % foo v
435
- 1.0.0
436
- ```
437
-
438
- ```shell
439
- % foo -v
440
- 1.0.0
441
- ```
442
-
443
- ```shell
444
- % foo --version
445
- 1.0.0
446
- ```
447
-
448
- ### Subcommand aliases
449
-
450
- ```shell
451
- % foo g config
452
- generated configuration
453
- ```
454
-
455
- ### Callbacks
456
-
457
- Third party gems can register _before_ and _after_ callbacks to enhance a command.
458
-
459
- From the `foo` gem we have a command `hello`.
460
-
461
- ```ruby
462
- #!/usr/bin/env ruby
463
- require "hanami/cli"
464
-
465
- module Foo
466
- module CLI
467
- module Commands
468
- extend Hanami::CLI::Registry
469
-
470
- class Hello < Hanami::CLI::Command
471
- argument :name, required: true
472
-
473
- def call(name:, **)
474
- puts "hello #{name}"
475
- end
476
- end
477
- end
478
- end
479
- end
480
-
481
- Foo::CLI::Commands.register "hello", Foo::CLI::Commands::Hello
482
-
483
- cli = Hanami::CLI.new(Foo::CLI::Commands)
484
- cli.call
485
- ```
486
-
487
- The `foo-bar` gem enhances `hello` command with callbacks:
488
-
489
- ```
490
- Foo::CLI::Commands.before("hello") { |args| puts "debug: #{args.inspect}" } # syntax 1
491
- Foo::CLI::Commands.after "hello", &->(args) { puts "bye, #{args.fetch(:name)}" } # syntax 2
492
- ```
493
-
494
- ```shell
495
- % foo hello Anton
496
- debug: {:name=>"Anton"}
497
- hello Anton
498
- bye, Anton
499
- ```
500
-
501
23
  ## Development
502
24
 
503
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
504
26
 
505
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
506
28
 
507
29
  ## Contributing
508
30
 
509
- Bug reports and pull requests are welcome on GitHub at https://github.com/hanami/cli.
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hanami/cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hanami/cli/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
510
36
 
511
- ## Alternatives
37
+ ## Code of Conduct
512
38
 
513
- * [thor](http://whatisthor.com/)
514
- * [clamp](https://github.com/mdub/clamp)
39
+ Everyone interacting in the Hanami::Cli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hanami/cli/blob/main/CODE_OF_CONDUCT.md).
515
40
 
516
41
  ## Copyright
517
42
 
518
- Copyright © 2017 Luca Guidi – Released under MIT License
43
+ Copyright © 2014-2021 Luca Guidi – Released under MIT License