Giter Site home page Giter Site logo

commander's Introduction

commander's People

Contributors

benbc avatar benedikt avatar brandondrew avatar ellemenno avatar fgalassi avatar ggilder avatar jonathonma avatar josephpecoraro avatar kethomassen avatar krausefx avatar krissi avatar marcandre avatar mattes avatar nwjsmith avatar parkr avatar rmc avatar rrrene avatar skytrix avatar suan avatar tj 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

commander's Issues

not working on windows

C:\Ruby\bin>jspec help
C:/Ruby/lib/ruby/gems/1.8/gems/commander-4.0.2/lib/commander/user_interaction.rb:198:in `fork': fork() function is unimplemented on this machine (NotImplementedError) from C:/Ruby/lib/ruby/gems/1.8/gems/commander-4.0.2/lib/commander/user_interaction.rb:198:in `enable_paging' [...]

Windows 7 64Bit, Ruby 1.8.7 win32-process-0.6.2 installed

Mandatory options?

Is it possible to specify an option which will be required in order to run command?

Include bash tab completion for commands

This just struck me as something very useful and practical to include as a feature. I'm only very vaguely familiar on how bash tab completion works, so I have no idea of the work it would involve. If its a significant effort though I might be willing to help - its something that I've always wanted in my scripts!

Add config support

Have --config or --options switch to supply a path. Also allow below, to specify auto-discovery paths for configurations.

program :config, ['.myprog/config.yml', '~/myprog/config.yml']

Allow undefined options to be present without blowing up

I have a case where the script may need options later on down the line, that I don't want to clog the command line options with them, and some I don't have control over (defined at runtime)/

I would like to be able to call something like this: ARGV.flag?('head'), which returns a boolean it it's defined or not. Simple enough to extend ARGV.

However, Commander will stop execution when it finds options it doesn't recognise. How do I go about changing this?

My app is going live soon, and I've tried several things, but so far, none of them have works. Can you help?

Regards
Kieran

Is this the correct behavior ?

Hi Tj:

I have looked over the commander docs about this behavior, without luck

I have a basic "commander init test.rb" script file here https://gist.github.com/1256555 and I added a second option '--no-some-switch'
when I run it

$ ruby test.rb testme --no-some-switch
<Commander::Command::Options no_some_switch=false>

option.no_some_switch is false

$ ruby test.rb testme --some-switch
<Commander::Command::Options some_switch=true>

option.no_some_switch is true

Should be true on both cases since I'm calling the option ?
Why the --no-* changes the boolean value ?

I'm using commander (4.0.6) with ruby-1.9.2-p180

Thanks

Easier way to deal with global_options

Appears the only way to deal with global_options currently is to handle them in every command block. Would be nice if you were able to do something like...

global_option('-f', '-foo FOO', 'The Desc Here') { |foo| $something = foo }

$something would truly be global and I could access this any where in my application, without having to deal with it in each command block.

c.option '-f', '--foo-bar' ... dash in option name issue

c.option '-f', '--foo-bar', String, 'A string for foo'
  c.action do |args, opts|
    opts.default \
      :'foo-bar' => 1 # looks kinda odd, doesn't it?
    puts opts.__hash__[:"foo-bar"] # only way to access value from --foo-bar

    # opts['foo-bar'] would be much appreciated ;-)
    # or something like opts.get('foo-bar')
  end

`converse` not working (OS X 10.7.4 Lion)

$ gem list commander
*** LOCAL GEMS ***
commander (4.1.2)
$ irb -r commander/import
irb(main):006:0> speak 'Hello' # works
=> #<Thread:0x007fd7d508a3b8 sleep>
irb(main):037:0> converse 'What is the best food?', # does not work
  :cookies => 'Cookies', :unknown => 'Nothing'
124:125: syntax error: Expected “given”, “into”, “with”, “without”, other
  parameter name, etc. but found "”. (-2741)
=> :""

RSpec 2 are supported

Hello,

Your .gemspec file defines, that RSpec < 2 are required, while the test suite seems to run just fine with the RSpec 2.x. Could you please update the .gemspec file accordingly?

Thanks.

--trace needs to be the first argument

When and error occurs and I do this:

something --verbose --trace

I get the following output:

Use --trace to view backtrace

However when I switch the arguments around:

something --trace --verbose

it outputs the full stack trace.

It would be nice not to have to have --trace first.

Subcommands?

I can't tell if this library supports subcommands. Does it, and if so, what is the syntax?

Avoiding Switch Clashes via OptionParser

Hey All,

Hopefully you can throw a suggestion out as to how I would solve this problem.

Currently have a global option --plugins with no explicit -p switch (OptionParser implicitly creates the -p switch as suggested by the documentation).

Later on there is a command option off of something called :serve which takes a --port or -p (explicitly defined).

So, when writing something like this

server --plugins "/foo" -p 1111

plugins gets all screwy because it now thinks it is supposed to look in the 111 directory.

Is there a way to get around this?

no such file to load -- commander/import (LoadError)

When I initialize a new commander on my machine, everything works flawlessly. However, when I try to use that script on another developer's machine, I always get this error:

/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- commander/import (LoadError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from ./plx.rb:4

What am I missing? My exact flow is, initialize, make a simple commander file, push to git repo, clone that repo on another machine and then try to run that script. I've also verified that the commander gem is installed on the new machine. Thanks in advance for any help and for an amazing tool!

Non-zero exit code on invalid command

Heyo. We use Commander for mojombo/jekyll and it turns out the InvalidCommandException, rescued and aborted again returns an exit code of 0, when it shouldn't.

Expected:

~/code/jekyll$ bin/jekyll buiild
invalid command. Use --help for more information
~/code/jekyll$ echo $?
1

Erroneous, current behaviour:

~/code/jekyll$ bin/jekyll buiild
invalid command. Use --help for more information
~/code/jekyll$ echo $?
0

Ref: jekyll/jekyll#1110

--

Hi!

Please, consider supporting '--'. Any stuff after '--' should go to arguments, even if it looks like an option

TIA,
--Vladimir

Extra newline character after output

Hi

I am getting an extra \n character after the output I am generating in the script. It is quite annoying since this script output needs to be processed and this makes me remove it manually. (grep -v ^$)

The version I am using is 4.1.3 (jruby 1.7.3 / mac os lion)

As an example, this script generates just a character (the newline) when called with the c command. It should not output anything.

require 'commander/import'
program :version, '1.0'
program :description, 'test of new line at the end'
program :help_formatter, :compact

command :c do |c|
  c.action do |args,options|
  end
end

Thanks!

Question : ctrl-c and listener

As Commander is able to intercept CTRL-C event (shutdown)

trap('INT') { abort program(:int_message) } if program(:int_message)

I would like to know if there is a event/listener available from Commander that we can use when such event occurs to call a method to kill a thread by example

The thread has been created when we have have call the function the first time the command has been received

c.action do |args, options|
Program::MyProject.process(options) # where we will create a Thread
end

The `find` statement fails on Windows

The following statement fails; user_interaction.rb line #240:

find {|name| system("hash #{name.split.first} 2>&-") }

I changed it to this, which now works:

find {|name| system("hash #{name.split.first} 2>&1") }

But, now I don't know where to find hash.. Is this a bash util or built-in lib somewhere? I tried gem install hash but it does not seem to be what it is looking for..

I'm running bro (on Windows) which uses commander..

Allow --help after commands

These are currently supported:

foobar help bar
foobar --help bar

Adding --help after the command should also be supported:

foobar bar --help

This matches git:

git help pull
git --help pull
git pull --help

Loading commander gem in a Rails 4 environment triggers: "DEPRECATION WARNING: RAILS_CACHE is deprecated!"

If I do require "commander" inside a Rails 4 app, I get this message:

DEPRECATION WARNING: RAILS_CACHE is deprecated! Use ::Rails.cache instead.

This seems to be a side-effect of how activesupport implements its deprecation mechanism. Commander goes through all global constants and calls respond_to? on them, triggering the deprecation warning for the RAILS_CACHE constant.

I'm not sure if this is a commander or an activesupport issue.

Here's the full trace in IRB:

$ rails c -s
Loading development environment in sandbox (Rails 4.0.0)
Any modifications you make will be rolled back on exit
>> ActiveSupport::Deprecation.debug = true
=> true
>> require 'commander'
DEPRECATION WARNING: RAILS_CACHE is deprecated! Use ::Rails.cache instead. (called from irb_binding at (irb):3)
/Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:330:in `block in <module:AskForClass>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:329:in `select'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:329:in `<module:AskForClass>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:322:in `<module:UI>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:13:in `<module:Commander>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander/user_interaction.rb:4:in `<top (required)>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/commander-4.1.4/lib/commander.rb:27:in `<top (required)>'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
  /Users/mbrictson/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
  (irb):3:in `irb_binding'

Ability to mark arguments and wether they are required/their type

Would be nice to be able to do this:

command :create_single do |c|
  c.argument :file, String, "The name of the file, without the ext"
  c.argument :ext, String, "The ext of the file"
  c.action do |file, ext, options|
    # the file/ext argment is mapped to the argument set, not an array (i.e. they return strings)
  end
end

Support for repeating ones too

command :create_multi do |c|
  c.arguments :files, List, "The name of the files, without the ext"
  c.action do |files, options|
    # the files value would be an array of the arguments
  end
end

You can only have one arguments declaration.

And it would be neat to mix the two and add the ability to mark required: (pay close attention to the args passed into the action block on this one, they show the outcome:

command :create_multi do |c|
  c.argument :base_file, String, "The file to base the other files on", :required => true
  c.arguments :files, List, "The name of the files, without the ext", :required => true
  c.argument :ext, String, "The ext of the file"
  c.action do |base_file, files, ext, options|
    # base_file => string
    # files => array
    # ext => string
    # options => hash
  end
end

An example usage of the above would be:

something create_multi base.rb file1 file2 file3 rbx

Note how base.rb and rbx would get mapped as strings, but the rest as array.

Deleting Global Options is Too Greedy

Given a global option like:

global_option('-b', '--beta', 'No argument') {}

Running the command:

shell> program -b 1 2

Provides the default command with arguments ["2"] instead of the expected ["1","2"].

Default command not always run when a global option is used

See here: https://github.com/DavidJRobertson/woody/blob/v0.4.0/bin/woody
I have in my Commander executable two commands, compile and deploy, with aliases c and d respectively. I also have a global option, --dir, and the default command is set to compile.

If I run the executable with no arguments/options, it correctly runs the compile command, however if I run it with no arguments and the --dir option, the deploy command is incorrectly executed.

Demo: http://ascii.io/a/1756

Correct Documentation for requires

Hi,

It appears Commander is now required with require commander/include, but the only way to know that is to look at the tests in /spec. Could you please update the README and the GitHub page to reflect that? It's a stumbling block for people wishing to use this awesome library.

Thank you for making Commander!

Reverse #when_called param order

Consider changing when_called so that

|args, options| 

becomes

|options, a, b, c| 

etc so that Ruby 1.9 users can take advantage of expanding args with 1.9.x param defaults

Stock generated script is not runnable

I'm not sure why commander tries to require 'myscript'in the generated template when I specify 'myscript' as the "Machine name" - I would think that for most commander use cases you're not looking to load a gem with the same name as your script...

In addition, the ':version' is not set to something correct, but is instead set to Myscript::VERSION.

These 2 things prevent a stock generated script from actually running without erroring out.

I propose removing the require statement, and setting the default version to '0.0.1'. Also, I think the "Machine name" prompt is unnecessary. Wouldn't it make sense to just use the filename of the file passed in as the init argument?

Don't mean to sound negative, but these things just seem bewildering to me :)

Should program version really be required?

I have a simple program:
#!/usr/bin/env ruby

require 'rubygems'
require 'commander/import'

pwd = password "Enter your password please:", '*'
puts pwd

which yields the following error when i run it:
/Library/Ruby/Gems/1.8/gems/commander-4.0.0/lib/commander/runner.rb:340:in `require_program': program version required (Commander::Runner::CommandError)

I believe that Commander should have some default for the program version (which is completely irrelevant in some cases), for example 1.0

Enabling --trace by default

It would be great to be able to enable --trace on all operations by default (namely for development, but also because I use my own exceptions which I need to fall through to the main app and currently get caught by Commander unless --trace is enabled)

Command name regular expressions

Would allow for:

command /foo(bar)?/ do 
  ...
end

where $ something foo and $ something foobar will both be called, capture groups should be available to the command

Avoiding global namespace pollution

Hi,

Can I suggest you add a means of configuring commander without polluting the global namespace. I expected to find something like:

require 'commander'

Commander.configure do
  program :name, 'Foobar'
  program :version, '1.0'
  # ...
  command :foo do
    # ...
  end
end

Can something like this please be added?

Removing --trace from the help file

--trace is great, but I don't want that option in the help file.

I still want it usable, but disabling the display of it should be configurable.

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.