karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Achim Nierbeck <bcanh...@googlemail.com>
Subject Re: Execute commands with arguments in Karaf
Date Fri, 26 Sep 2014 09:16:42 GMT
Hi,

you have to differ between options and arguments.
Options require the --username or shortcut if define -u
while arguments can be directly taken.

For example in your case it would be

create user test passwd

where the first argument is the user and the second the password
Though in this special case I'd make sure it's two different commands or
one command with a option --password, as a lot of unix style passwd
applications do it ;)

regards, Achim


2014-09-26 10:50 GMT+02:00 rcbandit <peter.penzov@gmail.com>:

> I have a question about creating commands in Karaf 3.0.2
>
> I created this simple example:
>
> @Command(scope = "kernel", name = "create", description = "create account")
> public class UsersShellCommands extends OsgiCommandSupport
> {
>
>     @Option(name = "user", aliases = { "user", "--user", "-u" },
> description
> = "Create user", required = false, multiValued = false)
>     String user;
>
>     @Option(name = "password", aliases = { "password", "--password", "-p"
> },
> description = "Create user password", required = false, multiValued =
> false)
>     String passwd;
>
>     @Override
>     protected Object doExecute() throws Exception
>     {
>         System.out.println("Username " + user + " password " + passwd);
>         return null;
>     }
> }
>
> I would like to use it this way:
>
> kernel:create user <username> password <passwd>
>
> But I get error
>
> karaf@root(kernel)> create user test password passwd
> Error executing command kernel:create: too many arguments specified
>
> I successfully can run this command:
>
> karaf@root(kernel)> create --user username --password passwd
> Username username password passwd
>
> Can you help me to find my mistake?
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Execute-commands-with-arguments-in-Karaf-tp4035537.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>



-- 

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message