-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI with default task and a required argument #370
Comments
I'm having the exact same problem, and haven't found a solution. I'd greatly appreciate any tips or tricks to working with this. Thanks! |
Hi, I am not sure if I understand the issue in here. |
We want to be able to have a command with absolutely no subcommand. For example, check out christianbundy/load. I'd like to be able to use the command:
Additionally,
|
I would also like this, and I find it strange that it's not already the behavior of default command to try to feed args that aren't commands into the default command. |
Same problem. |
First of all, I hope there will be some nicer way of doing it in future version of Thor. My quite ugly, but working workaround: #!/usr/bin/env ruby
require 'thor'
class MyApp < Thor
default_task :list
desc "TARGET_DIR", "List all files in directory and subdirectories"
def list(target_dir)
puts "Listing files in #{target_dir} now"
end
map %w[--version -v] => :version
desc "--version, -v", "Print the version"
def version
puts "#{MyApp} 0.0.1"
end
end
ARGV.unshift(MyApp.default_task) unless MyApp.all_tasks.has_key?(ARGV[0]) || MyApp.instance_variable_get(:@map).has_key?(ARGV[0])
MyApp.start(ARGV) With this class I can run it from command line:
|
I can't find the |
Why? Partly to get around needing workarounds such as rails/thor#370 (comment) for single-task Thor classes, and partly to make it easier to get useful CLI help. Before this change, the CLI help system worked like as follows: `bin/check_cocina help check_cocina`. Notice that to get help with a command, you would need to supply it twice. AFAIK, there is not a more Thor-like way to handle this... except to do what is done in this commit. Now `bin/sdr help check_cocina` does what you would expect and so does `bin/sdr help`.
I am creating a very simple CLI for my gem, and would like the user to be able to simply type a single word (name of the CLI), followed by some arguments, i.e.:
First question: is having my main class inherit from Thor::Group instead of Thor the only way to do this, as follows?
Given that script, I can run it as follows without trouble:
Second question: How can I make the help stop essentially listing the name of the CLI twice. Here is what "./test.rb --help" shows me:
I would rather it read simply:
To whit, this help would be even more awkward once I package into a gem, where the help would read something like:
The text was updated successfully, but these errors were encountered: