Git Product home page Git Product logo

cli's People

Contributors

bcardiff avatar eppo avatar mosop avatar paulosuzart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cli's Issues

Multiple inputs in one argument

Hi, i'm trying to copy the behavior of Javascript package managers in processing arguments e.g:

command install package1 package2

i tried to do it but what it outputs in the terminal is only the first item (because they are separated by a space not by a comma)

how can i achieve this?

Easy way to check if an option is set

Hi,

After reading the docs and the source, I couldn't find an easy way to check if an option is set or not.
For example, if I have this option:
string "-t", required: false

If I run without the "-t" flag but I want to check in my command if the flag is set, I can't do simply:
if options.t
I get a:
Missing hash key: "-t" (KeyError)

The only way I find is:
if options.__options__string.includes? "-t"
which is tedious to write.

Is there any other simpler solution for this?

Superoption

I like to implement:

command --option subcommand --suboption

and the subcommand command can get the --option option.

Validating args?

I'm looking at the example from optarg here https://github.com/mosop/optarg#custom-validation

Could you provide an example of this in cli? The best I could do was (example code):

class Exec < Cli::Command
  class Options
    string "--id", required: true

    Parser.on_validate do |parser|
      if parser.args.strings["--id"].to_i?.nil?
        parser.invalidate! "#{parser.args.strings["--id"]} is not an int"
      end
    end
  end
end

I feel parser.args.strings["--id"] is a bit clunky. It's matching on the exact string flag, with double -- in front, and not the nice options we get inside run. I'd love an example of validation inside the context of Cli.

Run from binary

In all examples the code is always executed programatically using #run method. Example:

MyClass.run %w(hello)

This is useful for examples and testing, but in real world I would like to do:

./binary hello

I couldn't find any example or documentation explaining how can I "initialize" my CLI in order to my binary run it instead of calling it from inside my code with #run methods.

How can I achieve that?

Args for default subcommand in a supercommand

With a structure like this:

include Cli

class To < SuperCommand
    command "go-to", default: true

    class GoTo < Command
        def run
          # ... 
        end
        class Options
            arg "where", required: true
        end   
    end

    class OtherCommand < Command
        def run
          # ... 
        end
    end

    class Help
        header "Goes to specified location"
    end

    class Options
        help
    end
end

Now if i were to run to homeโ€“ instead of running "go-to" with the argument "home" as "where"; it throws the help screen screen at me. Running to alone says i need to specify the where argument.
What about making it so if a default command is set and has (required?) arguments, it checks wether whatever is passed after supercommand invoke is a subcommand or not? If it is not, pass it as an argument to the default command.

Not working with crystal 0.30

The error is:

Error: abstract `def Enumerable(T)#each(&block)` must be implemented by Callback::ResultSet(T)

The code is one of your samples:

require "cli"
  
class Hello < Cli::Command
  class Options
    bool "--bye"
    arg "to"
  end

  def run
    if args.bye?
      print "Goodbye"
    else
      print "Hello"
    end
    puts " #{args.to}!"
  end
end

Hello.run %w(world) # prints "Hello, world!"
Hello.run %w(--bye world) # prints "Goodbye, world!"

Undefined method 'caption'

Hello, I'm getting an error with the exemple of subcommands from the readme
(https://github.com/mosop/cli#subcommands)

With the simple code (simplified) :

require "cli"

class Cake < Cli::Supercommand
  command "chocolat"

  class Options
    help
  end

  module Commands
    class Chocolat < Cli::Command
      caption "winter only" #error here
    end
  end
end

I get the error :

Error in ./src/cli_test.cr:12: undefined method 'caption'

      caption "winter only"
      ^~~~~~~

Thanks

Optional arguments formated the same way

Hi,

Is there a way to achieve someting like this :
cmd subcommand ARG [field[:type][:index] field[:type][:index]] [options]

Here is what I have :

  • cmd : Supercommand
  • subcommand : Command
  • ARG : arg "arg", required: true

Is there a way to do something like an array of infinite (or not) length with sub arguments : [field[:type][:index] field[:type][:index]] ?

My goal is to have this :
cmd subcommand Person age:integer:1 name role:string

Cannot import code from other file

Version

cli 0.6.10 (Crystal 0.23.1)

Problem

I'm trying to organize my code by splitting the commands into its own file (in a one module dedicated to commands) and the root app.cr file where the init would take place. But when I try to import the commands like this:

require "cli"
require "./myapp/*"

module MyApp
  class Myapp < Cli::Supercommand
    version VERSION

    class Options
      help
      version
    end

    include MyApp::Commands
  end

  Myapp.run ARGV
end

It doesn't work. I can't see any imported command popped up in the help section. Admiral (another cli lib) works just fine doing like this and I want to have a clean modular codebase so badly. Any Ideas? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.