Commandline: How to add an own option?

F

Fritz Trapper

I tried it this way, but it fails und the ducumentation is extremely
poor:

def initialize
version "0.0.1"
author "me"
copyright "2010, me"
synopsis "[-dh] log_file out_file"
short_description "A simple app example that takes two arguments."
long_description "app5 is a simple application"

option :version, :names => %w(--version -v)

# Here is my new option:
option :distance, :names => %w(--distance -d), :arity => [1,1],
:arg_description => "Distanz",
:eek:pt_description => "Maximale Entfernung [m]"

option :help
expected_args :log_file, :eek:ut_file
end

What is wrong with my option distance?
 
I

Intransition

I tried it this way, but it fails und the ducumentation is extremely
poor:

def initialize
=A0version =A0 =A0 =A0 =A0 =A0 "0.0.1"
=A0author =A0 =A0 =A0 =A0 =A0 =A0"me"
=A0copyright =A0 =A0 =A0 =A0 "2010, me"
=A0synopsis =A0 =A0 =A0 =A0 =A0"[-dh] log_file out_file"
=A0short_description "A simple app example that takes two arguments."
=A0long_description =A0"app5 is a simple application"

=A0option :version, :names =3D> %w(--version -v)

=A0# Here is my new option:
=A0option :distance, :names =3D> %w(--distance -d), :arity =3D> [1,1],
=A0 =A0:arg_description =3D> "Distanz",
=A0 =A0:eek:pt_description =3D> "Maximale Entfernung [m]"

=A0option :help
=A0expected_args =A0 :log_file, :eek:ut_file
end

You need to give more context then this. What code is this? As far as
I can tell it's just a error from word 'version'.
 
F

Fritz Trapper

Thomas Sawyer wrote in post #966397:
You need to give more context then this. What code is this? As far as
I can tell it's just a error from word 'version'.

OK, the context is:
-------------
#!/usr/bin/env ruby
require 'rubygems'
require 'commandline'

class App < CommandLine::Application
def initialize
< the body from my openining >
end
end
-------------

The code has been stolen from the rdoc of class CommandLine. The only
thing, I added to initialize was the statement

option :distance, :names => ...

w/o this, the code works, but I need an option distance for my app.

I don't think, that the error message:
ERROR: Unknown option setting 'distance'.
follows from the option :version, :names => %w(--version -v)
 
F

Fritz Trapper

Ok, the simplest way to overcome problems like this is, to dicard all
that obscure CommandLine::Application bullshit and handcode commandline
handling.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top