Skip to content
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

Handling and defining required args #49

Closed
DannyBen opened this issue Nov 12, 2019 · 2 comments · Fixed by #53
Closed

Handling and defining required args #49

DannyBen opened this issue Nov 12, 2019 · 2 comments · Fixed by #53

Comments

@DannyBen
Copy link

Hi,

I am not sure if this is currently possible - I haven't seen anything in the README.

Right now, it seems like required option flags are handled by Clim, while required arguments are not.

Is there a DSL command similar to option to define required args? I believe that having such a command would be beneficial in two ways:

  1. We can get arguments by their name, and not by their place.
  2. We will not need to handle missing arguments on our own, as it will be handled by Clim.

Example to demonstrate. Consider this code:

require "clim"

module Hello
  class Cli < Clim
    main do
      usage "hello <name>"
      
      run do |opts, args|
        if args.empty?
          puts opts.help_string
        else
          puts "hello #{args.first}"
        end
      end
    end
  end
end

Hello::Cli.start(ARGV)

Would be much nicer if it can be written like this:

main do
  usage "hello <name>"
  argument "name", type: String, required: true
  
  run do |opts, args|
    # We will not be in this block unless <name> is given
    puts "hello #{args.name}" # <- using args.name instead of args.first
  end
end
@at-grandpa
Copy link
Owner

@DannyBen
Thank you for a very good opinion!!
Let me think about it.

@at-grandpa
Copy link
Owner

Hi, @DannyBen .
It's now supported in the following versions!

https://github.com/at-grandpa/clim/releases/tag/v0.11.0

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants