tomo 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -29
- data/lib/tomo/cli.rb +1 -3
- data/lib/tomo/cli/common_options.rb +4 -12
- data/lib/tomo/cli/deploy_options.rb +2 -7
- data/lib/tomo/cli/parser.rb +1 -6
- data/lib/tomo/cli/project_options.rb +1 -3
- data/lib/tomo/cli/rules.rb +4 -22
- data/lib/tomo/cli/rules/argument.rb +2 -2
- data/lib/tomo/cli/rules/switch.rb +1 -5
- data/lib/tomo/cli/rules/value_switch.rb +2 -3
- data/lib/tomo/cli/rules_evaluator.rb +3 -13
- data/lib/tomo/cli/usage.rb +1 -3
- data/lib/tomo/commands/default.rb +1 -3
- data/lib/tomo/commands/init.rb +28 -1
- data/lib/tomo/commands/run.rb +1 -3
- data/lib/tomo/configuration.rb +6 -12
- data/lib/tomo/configuration/dsl/error_formatter.rb +1 -1
- data/lib/tomo/configuration/dsl/hosts_and_settings.rb +1 -2
- data/lib/tomo/configuration/plugins_registry.rb +1 -2
- data/lib/tomo/configuration/plugins_registry/gem_resolver.rb +1 -1
- data/lib/tomo/configuration/unknown_environment_error.rb +1 -4
- data/lib/tomo/console.rb +6 -11
- data/lib/tomo/console/menu.rb +1 -2
- data/lib/tomo/host.rb +1 -2
- data/lib/tomo/paths.rb +1 -1
- data/lib/tomo/plugin/bundler/tasks.rb +2 -7
- data/lib/tomo/plugin/core/helpers.rb +1 -1
- data/lib/tomo/plugin/core/tasks.rb +3 -12
- data/lib/tomo/plugin/env/tasks.rb +31 -9
- data/lib/tomo/plugin/git.rb +1 -4
- data/lib/tomo/plugin/git/tasks.rb +4 -14
- data/lib/tomo/plugin/nodenv/tasks.rb +1 -3
- data/lib/tomo/plugin/puma.rb +0 -3
- data/lib/tomo/plugin/puma/tasks.rb +6 -15
- data/lib/tomo/plugin/rails/tasks.rb +6 -4
- data/lib/tomo/plugin/rbenv/tasks.rb +16 -2
- data/lib/tomo/plugin/testing.rb +1 -3
- data/lib/tomo/remote.rb +1 -3
- data/lib/tomo/runtime.rb +3 -6
- data/lib/tomo/runtime/concurrent_ruby_thread_pool.rb +1 -4
- data/lib/tomo/runtime/execution_plan.rb +1 -4
- data/lib/tomo/runtime/explanation.rb +1 -7
- data/lib/tomo/runtime/settings_required_error.rb +1 -3
- data/lib/tomo/runtime/task_runner.rb +1 -5
- data/lib/tomo/runtime/unknown_task_error.rb +1 -4
- data/lib/tomo/script.rb +1 -5
- data/lib/tomo/shell_builder.rb +5 -10
- data/lib/tomo/ssh/child_process.rb +2 -7
- data/lib/tomo/ssh/connection.rb +5 -18
- data/lib/tomo/ssh/connection_validator.rb +5 -8
- data/lib/tomo/ssh/executable_error.rb +1 -2
- data/lib/tomo/ssh/options.rb +2 -5
- data/lib/tomo/task_api.rb +4 -15
- data/lib/tomo/templates/config.rb.erb +9 -1
- data/lib/tomo/testing/cli_extensions.rb +1 -1
- data/lib/tomo/testing/connection.rb +1 -6
- data/lib/tomo/testing/docker_image.rb +5 -11
- data/lib/tomo/testing/local.rb +1 -3
- data/lib/tomo/testing/ubuntu_setup.sh +1 -2
- data/lib/tomo/version.rb +1 -1
- metadata +8 -135
- data/lib/tomo/configuration/plugin_resolver.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e70a81efc32a7a80b37b26edc668de8daa510e7954884a3711d71ced6ef1bf8
|
4
|
+
data.tar.gz: eef6788e4b36c1cdad66170b6b616af8a08f890bc089a6c70e6a12132a061911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4425384a896b364775994859d7ea4307cac1abcbd507514d6f7289d6a684f6263cd7b17d250d280f6f2ccd596ed47f5d8f0871337dd5b69895aa74a0ea9c718e
|
7
|
+
data.tar.gz: 57a0929d3e1be161c7830449226327ee1c4f0e20f4949658ec02287c436c4fbb12e8a7f819a4525266beb29a8abd6381285aae27e21b6e753ac27028783dca1f
|
data/README.md
CHANGED
@@ -2,25 +2,25 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/tomo.svg)](https://rubygems.org/gems/tomo)
|
4
4
|
[![Travis](https://img.shields.io/travis/mattbrictson/tomo.svg?label=travis)](https://travis-ci.org/mattbrictson/tomo)
|
5
|
-
[![Circle](https://circleci.com/gh/mattbrictson/tomo.svg?style=shield)](https://app.circleci.com/pipelines/github/mattbrictson/tomo?branch=
|
5
|
+
[![Circle](https://circleci.com/gh/mattbrictson/tomo/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/mattbrictson/tomo?branch=main)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/mattbrictson/tomo/badges/gpa.svg)](https://codeclimate.com/github/mattbrictson/tomo)
|
7
7
|
|
8
|
-
Tomo is a friendly command-line tool for deploying Rails apps.
|
8
|
+
Tomo is a friendly command-line tool for deploying Rails apps.
|
9
9
|
|
10
10
|
💻 Rich command-line interface with built-in bash completions<br/>
|
11
11
|
☁️ Multi-environment and role-based multi-host support<br/>
|
12
12
|
💎 Everything you need to deploy a basic Rails app out of the box<br/>
|
13
13
|
🔌 Easily extensible for polyglot projects (not just Rails!)<br/>
|
14
|
-
💡 Concise, helpful error messages<br/>
|
15
14
|
📚 Quality documentation<br/>
|
16
15
|
🔬 Minimal dependencies<br/>
|
17
16
|
|
18
|
-
See
|
17
|
+
[→ See how tomo compares to other Ruby deployment tools like Capistrano and Mina.](https://tomo-deploy.com/comparisons/)
|
19
18
|
|
20
19
|
---
|
21
20
|
|
22
21
|
- [Quick start](#quick-start)
|
23
22
|
- [Usage](#usage)
|
23
|
+
- [Extending tomo](#extending-tomo)
|
24
24
|
- [Tutorials](#tutorials)
|
25
25
|
- [Reference documentation](#reference-documentation)
|
26
26
|
- [FAQ](#faq)
|
@@ -31,21 +31,19 @@ See [how tomo compares](https://tomo-deploy.com/comparisons/) to other Ruby depl
|
|
31
31
|
|
32
32
|
## Quick start
|
33
33
|
|
34
|
+
#### Installation
|
35
|
+
|
34
36
|
Tomo is distributed as a ruby gem. To install:
|
35
37
|
|
36
38
|
```
|
37
39
|
$ gem install tomo
|
38
40
|
```
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
```
|
43
|
-
$ tomo completion-script
|
44
|
-
```
|
42
|
+
> 💡 **Protip:** run `tomo completion-script` for instructions on setting up bash completions.
|
45
43
|
|
46
44
|
#### Configuring a project
|
47
45
|
|
48
|
-
Tomo is configured via a `.tomo/config.rb` file in your project. To get started,
|
46
|
+
Tomo is configured via a `.tomo/config.rb` file in your project. To get started, run `tomo init` to generate a configuration that works for a basic Rails app.
|
49
47
|
|
50
48
|
![$ tomo init](./readme_images/tomo-init.png)
|
51
49
|
|
@@ -64,7 +62,7 @@ host "user@hostname.or.ip.address"
|
|
64
62
|
set application: "my-rails-app"
|
65
63
|
set deploy_to: "/var/www/%{application}"
|
66
64
|
set git_url: "git@github.com:my-username/my-rails-app.git"
|
67
|
-
set git_branch: "
|
65
|
+
set git_branch: "main"
|
68
66
|
# ...
|
69
67
|
|
70
68
|
setup do
|
@@ -87,20 +85,25 @@ deploy do
|
|
87
85
|
end
|
88
86
|
```
|
89
87
|
|
90
|
-
|
88
|
+
#### Next steps
|
89
|
+
|
90
|
+
[→ The reference docs have a complete guide to tomo configuration.](https://tomo-deploy.com/configuration/)<br>
|
91
|
+
[→ Check out the **Deploying Rails From Scratch** tutorial for a step-by-step guide to using tomo with a real app.](https://tomo-deploy.com/tutorials/deploying-rails-from-scratch/)
|
91
92
|
|
92
93
|
## Usage
|
93
94
|
|
94
|
-
|
95
|
+
Once your project is configured, you can:
|
96
|
+
|
97
|
+
1. Run `tomo setup` to prepare the remote host for its first deploy.
|
98
|
+
2. Run `tomo deploy` to deploy your app.
|
99
|
+
3. Use `tomo run` to invoke one-off tasks, like launching a Rails console.
|
95
100
|
|
96
|
-
|
97
|
-
2. `tomo deploy` performs a deployment
|
98
|
-
3. `tomo run` lets you invoke one-off tasks
|
101
|
+
> 💡 **Protip:** add `-h` or `--help` when running any of these commands to see detailed docs and examples.
|
99
102
|
|
100
|
-
###
|
103
|
+
### `tomo setup`
|
101
104
|
|
102
105
|
`tomo setup` prepares the remote host for its first deploy by sequentially running the
|
103
|
-
|
106
|
+
`setup` list of tasks specified in `.tomo/config.rb`. These tasks typically create directories, initialize data stores, install prerequisite tools, and perform other one-time actions that are necessary before a deploy can take place.
|
104
107
|
|
105
108
|
Out of the box, tomo will:
|
106
109
|
|
@@ -109,9 +112,12 @@ Out of the box, tomo will:
|
|
109
112
|
- Create all necessary deployment directories
|
110
113
|
- Create the Rails database, load the schema, and insert seed data
|
111
114
|
|
112
|
-
|
115
|
+
[→ Here is the default list of tasks invoked by the setup command.](https://tomo-deploy.com/configuration#setupblock)<br>
|
116
|
+
[→ The `tomo setup` section of the reference docs explains supported command-line options.](https://tomo-deploy.com/commands/setup/)
|
113
117
|
|
114
|
-
|
118
|
+
### `tomo deploy`
|
119
|
+
|
120
|
+
Whereas `tomo setup` is typically run once, you can use `tomo deploy` every time you want to deploy a new version of your app. The deploy command will sequentially run the `deploy` list of tasks specified in `.tomo/config.rb`. You can customize this list to meet the needs of your app. By default, tomo runs these tasks:
|
115
121
|
|
116
122
|
1. Create a release (using the [git:create_release](https://tomo-deploy.com/plugins/git#gitcreate_release) task)
|
117
123
|
2. Build the project (e.g. [bundler:install](https://tomo-deploy.com/plugins/bundler#bundlerinstall), [rails:assets_precompile](https://tomo-deploy.com/plugins/rails#railsassets_precompile))
|
@@ -120,7 +126,13 @@ Whereas `tomo setup` is typically run once, you can use `tomo deploy` every time
|
|
120
126
|
5. Restart the app to use the new current release (e.g. [puma:restart](https://tomo-deploy.com/plugins/puma#pumarestart))
|
121
127
|
6. Perform any cleanup (e.g. [bundler:clean](https://tomo-deploy.com/plugins/bundler#bundlerclean))
|
122
128
|
|
123
|
-
|
129
|
+
> 💡 **Protip:** you can abbreviate tomo commands, like `tomo d` for `tomo deploy` or `tomo s` for `tomo setup`.
|
130
|
+
|
131
|
+
[→ Here is the default list of tasks invoked by the deploy command.](https://tomo-deploy.com/configuration#deployblock)<br>
|
132
|
+
[→ The `tomo deploy` section of the reference docs explains supported command-line options, like `--dry-run`.](https://tomo-deploy.com/commands/deploy/)
|
133
|
+
|
134
|
+
|
135
|
+
### `tomo run [TASK]`
|
124
136
|
|
125
137
|
Tomo can also `run` individual remote tasks on demand. You can use the `tasks` command to see the list of tasks tomo knows about.
|
126
138
|
|
@@ -130,9 +142,15 @@ One of the built-in Rails tasks is `rails:console`, which brings up a fully-inte
|
|
130
142
|
|
131
143
|
![$ tomo run rails:console](./readme_images/tomo-run-rails-console.png)
|
132
144
|
|
133
|
-
|
145
|
+
> 💡 **Protip:** you can shorten this as `tomo rails:console` (the `run` command is implied).
|
146
|
+
|
147
|
+
[→ The `tomo run` section of the reference docs explains supported command-line options and has more examples.](https://tomo-deploy.com/commands/run/)
|
148
|
+
|
134
149
|
|
135
|
-
|
150
|
+
|
151
|
+
## Extending tomo
|
152
|
+
|
153
|
+
Tomo has a powerful plugin system that lets you extend tomo by installing Ruby gems (e.g. [tomo-plugin-sidekiq](https://github.com/mattbrictson/tomo-plugin-sidekiq)). You can also define plugins on the fly within your project by adding simple `.rb` files to `.tomo/plugins/`. These plugins can define tasks as plain ruby methods. For example:
|
136
154
|
|
137
155
|
```ruby
|
138
156
|
# .tomo/plugins/my-plugin.rb
|
@@ -142,8 +160,6 @@ def hello
|
|
142
160
|
end
|
143
161
|
```
|
144
162
|
|
145
|
-
Use `remote.run` to execute shell scripts on the remote host, similar to how you would use Ruby's `system`. Project settings are accessible via `settings`, which is a plain Ruby hash.
|
146
|
-
|
147
163
|
Load your plugin in `config.rb` like this:
|
148
164
|
|
149
165
|
```ruby
|
@@ -156,7 +172,9 @@ And run it!
|
|
156
172
|
|
157
173
|
![$ tomo run my-plugin:hello](./readme_images/tomo-run-hello.png)
|
158
174
|
|
159
|
-
|
175
|
+
[→ The **Writing Custom Tasks** tutorial has an in-depth explanation of how plugins work.](https://tomo-deploy.com/tutorials/writing-custom-tasks/)<br>
|
176
|
+
[→ The **TaskLibrary** API is tomo's DSL for building tasks.](https://tomo-deploy.com/api/TaskLibrary/)<br>
|
177
|
+
[→ The **Publishing a Plugin** tutorial explains how to package your plugin as a Ruby gem to share it with the community.](https://tomo-deploy.com/tutorials/publishing-a-plugin/)
|
160
178
|
|
161
179
|
## Tutorials
|
162
180
|
|
@@ -225,7 +243,7 @@ Next run `tomo setup` for _both_ apps; this will set everything up for both user
|
|
225
243
|
|
226
244
|
## Support
|
227
245
|
|
228
|
-
This project is a labor of love and I can only spend a few hours a week maintaining it, at most. If you'd like to help by submitting a pull request, or if you've discovered a bug that needs my attention, please let me know. Check out [CONTRIBUTING.md](https://github.com/mattbrictson/tomo/blob/
|
246
|
+
This project is a labor of love and I can only spend a few hours a week maintaining it, at most. If you'd like to help by submitting a pull request, or if you've discovered a bug that needs my attention, please let me know. Check out [CONTRIBUTING.md](https://github.com/mattbrictson/tomo/blob/main/CONTRIBUTING.md) to get started. Happy hacking! —Matt
|
229
247
|
|
230
248
|
## License
|
231
249
|
|
@@ -233,8 +251,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
233
251
|
|
234
252
|
## Code of conduct
|
235
253
|
|
236
|
-
Everyone interacting in the Tomo project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mattbrictson/tomo/blob/
|
254
|
+
Everyone interacting in the Tomo project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mattbrictson/tomo/blob/main/CODE_OF_CONDUCT.md).
|
237
255
|
|
238
256
|
## Contribution guide
|
239
257
|
|
240
|
-
Interested in filing a bug report, feature request, or opening a PR? Excellent! Please read the short [CONTRIBUTING.md](https://github.com/mattbrictson/tomo/blob/
|
258
|
+
Interested in filing a bug report, feature request, or opening a PR? Excellent! Please read the short [CONTRIBUTING.md](https://github.com/mattbrictson/tomo/blob/main/CONTRIBUTING.md) guidelines before you dive in.
|
data/lib/tomo/cli.rb
CHANGED
@@ -20,7 +20,7 @@ module Tomo
|
|
20
20
|
class << self
|
21
21
|
attr_accessor :show_backtrace
|
22
22
|
|
23
|
-
def exit(status=true)
|
23
|
+
def exit(status=true) # rubocop:disable Style/OptionalBooleanParameter
|
24
24
|
Process.exit(status)
|
25
25
|
end
|
26
26
|
end
|
@@ -55,7 +55,6 @@ module Tomo
|
|
55
55
|
argv << "" if argv.shift == "--complete"
|
56
56
|
end
|
57
57
|
|
58
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
59
58
|
def lookup_command(argv)
|
60
59
|
command_name = argv.first unless Completions.active? && argv.length == 1
|
61
60
|
command_name = Abbrev.abbrev(COMMANDS.keys)[command_name]
|
@@ -65,7 +64,6 @@ module Tomo
|
|
65
64
|
command = COMMANDS[command_name] || Tomo::Commands::Default
|
66
65
|
[command, command_name]
|
67
66
|
end
|
68
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
69
67
|
|
70
68
|
def task_format?(arg)
|
71
69
|
arg.to_s.match?(/\A\S+:\S*\z/)
|
@@ -1,22 +1,15 @@
|
|
1
1
|
module Tomo
|
2
2
|
class CLI
|
3
3
|
module CommonOptions
|
4
|
-
# rubocop:disable Metrics/MethodLength
|
5
|
-
def self.included(mod)
|
4
|
+
def self.included(mod) # rubocop:disable Metrics/MethodLength
|
6
5
|
mod.class_eval do
|
7
|
-
option :color,
|
8
|
-
"--[no-]color",
|
9
|
-
"Enable/disable color output" do |color|
|
6
|
+
option :color, "--[no-]color", "Enable/disable color output" do |color|
|
10
7
|
Colors.enabled = color
|
11
8
|
end
|
12
|
-
option :debug,
|
13
|
-
"--[no-]debug",
|
14
|
-
"Enable/disable verbose debug logging" do |debug|
|
9
|
+
option :debug, "--[no-]debug", "Enable/disable verbose debug logging" do |debug|
|
15
10
|
Tomo.debug = debug
|
16
11
|
end
|
17
|
-
option :trace,
|
18
|
-
"--[no-]trace",
|
19
|
-
"Display full backtrace on error" do |trace|
|
12
|
+
option :trace, "--[no-]trace", "Display full backtrace on error" do |trace|
|
20
13
|
CLI.show_backtrace = trace
|
21
14
|
end
|
22
15
|
option :help, "-h, --help", "Print this documentation" do |_help|
|
@@ -27,7 +20,6 @@ module Tomo
|
|
27
20
|
after_parse :dump_runtime_info
|
28
21
|
end
|
29
22
|
end
|
30
|
-
# rubocop:enable Metrics/MethodLength
|
31
23
|
|
32
24
|
private
|
33
25
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Tomo
|
2
2
|
class CLI
|
3
3
|
module DeployOptions
|
4
|
-
# rubocop:disable Metrics/MethodLength
|
5
|
-
def self.included(mod)
|
4
|
+
def self.included(mod) # rubocop:disable Metrics/MethodLength
|
6
5
|
mod.class_eval do
|
7
6
|
option :environment,
|
8
7
|
"-e, --environment ENVIRONMENT",
|
@@ -23,7 +22,6 @@ module Tomo
|
|
23
22
|
after_parse :prompt_for_environment
|
24
23
|
end
|
25
24
|
end
|
26
|
-
# rubocop:enable Metrics/MethodLength
|
27
25
|
|
28
26
|
private
|
29
27
|
|
@@ -49,10 +47,7 @@ module Tomo
|
|
49
47
|
return if envs.empty?
|
50
48
|
return unless Console.interactive?
|
51
49
|
|
52
|
-
options[:environment] = Console.menu(
|
53
|
-
"Choose an environment:",
|
54
|
-
choices: envs
|
55
|
-
)
|
50
|
+
options[:environment] = Console.menu("Choose an environment:", choices: envs)
|
56
51
|
end
|
57
52
|
end
|
58
53
|
end
|
data/lib/tomo/cli/parser.rb
CHANGED
@@ -46,12 +46,7 @@ module Tomo
|
|
46
46
|
attr_reader :rules, :usage, :after_parse_methods
|
47
47
|
|
48
48
|
def evaluate(argv, state, literal:)
|
49
|
-
RulesEvaluator.evaluate(
|
50
|
-
rules: rules.to_a,
|
51
|
-
argv: argv,
|
52
|
-
state: state,
|
53
|
-
literal: literal
|
54
|
-
)
|
49
|
+
RulesEvaluator.evaluate(rules: rules.to_a, argv: argv, state: state, literal: literal)
|
55
50
|
end
|
56
51
|
|
57
52
|
def check_required_rules(state)
|
@@ -3,9 +3,7 @@ module Tomo
|
|
3
3
|
module ProjectOptions
|
4
4
|
def self.included(mod)
|
5
5
|
mod.class_eval do
|
6
|
-
option :project,
|
7
|
-
"-c, --config PATH",
|
8
|
-
"Location of project config (default: #{DEFAULT_CONFIG_PATH})"
|
6
|
+
option :project, "-c, --config PATH", "Location of project config (default: #{DEFAULT_CONFIG_PATH})"
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
data/lib/tomo/cli/rules.rb
CHANGED
@@ -51,21 +51,11 @@ module Tomo
|
|
51
51
|
attr_reader :rules
|
52
52
|
|
53
53
|
def optional_arg_rule(spec, values_proc)
|
54
|
-
Rules::Argument.new(
|
55
|
-
spec,
|
56
|
-
values_proc: values_proc,
|
57
|
-
required: false,
|
58
|
-
multiple: false
|
59
|
-
)
|
54
|
+
Rules::Argument.new(spec, values_proc: values_proc, required: false, multiple: false)
|
60
55
|
end
|
61
56
|
|
62
57
|
def required_arg_rule(spec, values_proc)
|
63
|
-
Rules::Argument.new(
|
64
|
-
spec,
|
65
|
-
values_proc: values_proc,
|
66
|
-
required: true,
|
67
|
-
multiple: false
|
68
|
-
)
|
58
|
+
Rules::Argument.new(spec, values_proc: values_proc, required: true, multiple: false)
|
69
59
|
end
|
70
60
|
|
71
61
|
def mutiple_optional_args_rule(spec, values_proc)
|
@@ -73,10 +63,7 @@ module Tomo
|
|
73
63
|
end
|
74
64
|
|
75
65
|
def on_off_switch_rule(key, name, _values_proc, callback_proc)
|
76
|
-
Rules::Switch.new(key,
|
77
|
-
"--#{name}",
|
78
|
-
"--no-#{name}",
|
79
|
-
callback_proc: callback_proc) do |arg|
|
66
|
+
Rules::Switch.new(key, "--#{name}", "--no-#{name}", callback_proc: callback_proc) do |arg|
|
80
67
|
arg == "--#{name}"
|
81
68
|
end
|
82
69
|
end
|
@@ -86,12 +73,7 @@ module Tomo
|
|
86
73
|
end
|
87
74
|
|
88
75
|
def value_switch_rule(key, *switches, values_proc, callback_proc)
|
89
|
-
Rules::ValueSwitch.new(
|
90
|
-
key,
|
91
|
-
*switches,
|
92
|
-
values_proc: values_proc,
|
93
|
-
callback_proc: callback_proc
|
94
|
-
)
|
76
|
+
Rules::ValueSwitch.new(key, *switches, values_proc: values_proc, callback_proc: callback_proc)
|
95
77
|
end
|
96
78
|
end
|
97
79
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Tomo::CLI::Rules
|
2
2
|
class Argument
|
3
|
-
def initialize(label, multiple: false, required: false
|
3
|
+
def initialize(label, values_proc:, multiple: false, required: false)
|
4
4
|
@label = label
|
5
5
|
@multiple = multiple
|
6
6
|
@required = required
|
@@ -15,7 +15,7 @@ class Tomo::CLI::Rules
|
|
15
15
|
state.parsed_arg(arg)
|
16
16
|
end
|
17
17
|
|
18
|
-
def candidates(literal: false
|
18
|
+
def candidates(state:, literal: false)
|
19
19
|
values(state).reject { |val| literal && val.start_with?("-") }
|
20
20
|
end
|
21
21
|
|
@@ -1,10 +1,6 @@
|
|
1
1
|
class Tomo::CLI::Rules
|
2
2
|
class Switch
|
3
|
-
def initialize(key,
|
4
|
-
*switches,
|
5
|
-
required: false,
|
6
|
-
callback_proc:,
|
7
|
-
&convert_proc)
|
3
|
+
def initialize(key, *switches, callback_proc:, required: false, &convert_proc)
|
8
4
|
@key = key
|
9
5
|
@switches = switches
|
10
6
|
@callback_proc = callback_proc
|
@@ -28,7 +28,7 @@ class Tomo::CLI::Rules
|
|
28
28
|
state.parsed_option(key, value)
|
29
29
|
end
|
30
30
|
|
31
|
-
def candidates(switch=nil, literal: false
|
31
|
+
def candidates(switch=nil, state:, literal: false)
|
32
32
|
return [] if literal
|
33
33
|
|
34
34
|
vals = values(state)
|
@@ -51,8 +51,7 @@ class Tomo::CLI::Rules
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def raise_missing_value(switch)
|
54
|
-
raise Tomo::CLI::Error,
|
55
|
-
"Please specify a value for the #{yellow(switch)} option."
|
54
|
+
raise Tomo::CLI::Error, "Please specify a value for the #{yellow(switch)} option."
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -41,11 +41,7 @@ module Tomo
|
|
41
41
|
def complete_if_needed(matched_rules, *matched_args)
|
42
42
|
return unless Completions.active?
|
43
43
|
|
44
|
-
completions.print_completions_and_exit(
|
45
|
-
matched_rules,
|
46
|
-
*matched_args,
|
47
|
-
state: state
|
48
|
-
)
|
44
|
+
completions.print_completions_and_exit(matched_rules, *matched_args, state: state)
|
49
45
|
end
|
50
46
|
|
51
47
|
def remaining_rules
|
@@ -56,15 +52,9 @@ module Tomo
|
|
56
52
|
|
57
53
|
def raise_unrecognized_args
|
58
54
|
problem_arg = argv.first
|
59
|
-
type =
|
60
|
-
"arg"
|
61
|
-
else
|
62
|
-
"option"
|
63
|
-
end
|
55
|
+
type = literal || !problem_arg.start_with?("-") ? "arg" : "option"
|
64
56
|
|
65
|
-
raise CLI::Error,
|
66
|
-
"#{Colors.yellow(problem_arg)} is not a recognized #{type} "\
|
67
|
-
"for this tomo command."
|
57
|
+
raise CLI::Error, "#{Colors.yellow(problem_arg)} is not a recognized #{type} for this tomo command."
|
68
58
|
end
|
69
59
|
end
|
70
60
|
end
|
data/lib/tomo/cli/usage.rb
CHANGED