parsing sub command args from args

8 views
Skip to first unread message

Shashank Mutalik

unread,
Jun 12, 2018, 6:40:46 AM6/12/18
to jopt-simple
Hi,

I have a scenario where below is happening:

Command to be parsed is something like below:

/opt/ORCLemaas/InfrastructureSoftware/java/jdk/bin/java  -cp /opt/ORCLemaas/emcs/lcm/lifecycle-manager-client.jar:/opt/ORCLemaas/emcs/lcm/provisioning-service.jar:/opt/ORCLemaas/InfrastructureSoftware/pregistry/0.1/credential-provider-sdk-1.x.jar:/opt/ORCLemaas/InfrastructureSoftware/pregistry/0.1/credential-consumer-sdk-1.x.jar -Dlog4j.configurationFile=/opt/ORCLemaas/InfrastructureSoftware/pregistry/1.0.0/empty-log4j2-logger.xml oracle.sysman.emaas.platform.simpleclient.CommandExecutorClient -inputCommandFile /opt/ORCLemaas/emcs/lcm/upgrade.init -cloudHostName den00yoa.us.oracle.com -cloudTierArgs "-verbose true -skipAgentPublish false -stackPatchAlongWithUpdate true" -gwayTierArgs "-verbose true -stackPatchAlongWithUpdate true" -phase upgrade -patchOp patch

As you can see above, we have an option and subsequent option to another program/script in the args:

-cloudTierArgs "-verbose true -skipAgentPublish false -stackPatchAlongWithUpdate true"

The problem I now have is that I cannot define my list of recognized options with any of the options that I have passed as args, i.e, if I have something as recognized option(for example -saasVersion), it is taking "-s" as a short option from "-skipAgentPublish" and "-stackPatchAlongWithUpdate" options.

I tried posixlyCorrect flag but in that case it foregoing all the passed args as unrecognized. My Parser defn is as below:

protected OptionSpec<String> _inputCommandFile = null;
protected OptionSpec<String> _executionMethod = null;
protected OptionSpec<String> _timeoutInHours = null;
        protected OptionSpec<String> _cloudTierArgs = null;
        protected OptionSpec<String> _gwayTierArgs = null;
        protected OptionSpec<String> _cloudHostName = null;
        protected OptionSpec<String> _gwayHostName = null;
        protected OptionSpec<String> _phase = null;
        protected OptionSpec<String> _patchPhase = null;
        protected OptionSpec<String> _saasVersion = null;
        protected OptionSpec<String> _idoruUrl = null;
protected OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
                _inputCommandFile = parser.accepts(c_inputCommandFile).withRequiredArg().ofType(String.class)
.describedAs("location of input command file.");
_executionMethod = parser.accepts(c_executionMethod).withOptionalArg().ofType(String.class).describedAs(" execution method parallel/serial");
                _cloudTierArgs = parser.accepts(c_cloudTierArgs).withOptionalArg().ofType(String.class).describedAs(" cloud upgrade args").withValuesSeparatedBy(" ");                
                _gwayTierArgs = parser.accepts(c_gwayTierArgs).withOptionalArg().ofType(String.class).describedAs(" gwaytier upgrade args").withValuesSeparatedBy(" ");
                _cloudHostName = parser.accepts(c_cloudHostName).withOptionalArg().ofType(String.class).describedAs(" cloud smp node hostname");
                _phase = parser.accepts(c_phase).withOptionalArg().ofType(String.class).describedAs(" upgrade phase");
                _patchPhase = parser.accepts(c_patchPhase).withOptionalArg().ofType(String.class).describedAs(" patching phase");
                _saasVersion = parser.accepts(c_saasVersion).withOptionalArg().ofType(String.class).describedAs(" saas version for upgrade");
                _idoruUrl = parser.accepts(c_idoruUrl).withOptionalArg().ofType(String.class).describedAs(" artifactory url");
                
String s="";
                for (String str: args) {
                    s = s+ " " + str;
                }
                System.out.println("The args passed is:");
                System.out.println(s);
CommandArguments commandArgs = new CommandArguments();
OptionSet optionSet = parser.parse(args);
                //System.out.println("The size of the list: " + optionSet.nonOptionArguments().size());
                //System.out.println("The list is: " );
                List<?> al = optionSet.nonOptionArguments();

We want to be able to define "-saasVersion" as a recognized option and at the same time pass "skipAgentPublish false -stackPatchAlongWithUpdate true" to any other recognized option that is defined.

We are using jopt-simple-4.6.jar in our code base.

Any help on this would be really appreciated!!

Thanks,
Shashank

Shashank Mutalik

unread,
Jun 15, 2018, 5:32:18 AM6/15/18
to jopt-simple
Folks,

Can anyone please guide me on this?

Thanks,
Shashank
Reply all
Reply to author
Forward
0 new messages