org.ASUX.yaml.CmdLineArgsBatchCmd Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yaml Show documentation
Show all versions of yaml Show documentation
Cmdline interface to process YAML files, leveraging the brilliantly robust gitbub project github.com:esotericsoftware/yamlbeans.git (which is a Java object graphs, to and from YAML)
/*
BSD 3-Clause License
Copyright (c) 2019, Udaybhaskar Sarma Seetamraju
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.ASUX.yaml;
import org.apache.commons.cli.*;
/** This class is a typical use of the org.apache.commons.cli package.
* This class has No other function - other than to parse the commandline arguments and handle user's input errors.
* For making it easy to have simple code generate debugging-output, added a toString() method to this class.
* Typical use of this class is:
*
public static void main(String[] args) {
CmdLineArgsBatchCmd = new CmdLineArgsBatchCmd(args);
.. ..
*
*
* See full details of how to use this, in {@link org.ASUX.yaml.Cmd} as well as the org.ASUX.cmdline GitHub.com project.
* @see org.ASUX.yaml.Cmd
*/
public class CmdLineArgsBatchCmd extends CmdLineArgs {
private static final long serialVersionUID = 334L;
public static final String CLASSNAME = CmdLineArgsBatchCmd.class.getName();
public String batchFilePath = null; // Required for 'batch' command
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/** Constructor.
* @param _cmdType enum denoting what the user's command-type was, as entered on the command line
* @param _shortCmd example "r" "zd"
* @param _longCmd example "read" "table"
* @param _cmdDesc long description. See org.apache.commons.cli for complex examples.
* @param _numArgs the # of additional arguments following this command
* @param _addlArgsDesc what the HELP command shows about these additional args
* @throws Exception like ClassNotFoundException while trying to serialize and deserialize the input-parameter
*/
public CmdLineArgsBatchCmd( final Enums.CmdEnum _cmdType,
final String _shortCmd, final String _longCmd, final String _cmdDesc,
final int _numArgs, final String _addlArgsDesc )
throws Exception
{
super( _cmdType, _shortCmd, _longCmd, _cmdDesc, _numArgs, _addlArgsDesc );
} // method
//=================================================================================
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//=================================================================================
/**
* @see org.ASUX.yaml.CmdLineArgsCommon#parseAdditionalOptions
*/
@Override
protected void parseAdditionalOptions( String[] _args, final org.apache.commons.cli.CommandLine _apacheCmdProcessor )
throws MissingOptionException, ParseException, Exception
{
super.parseAdditionalOptions(_args, _apacheCmdProcessor);
this.batchFilePath = _apacheCmdProcessor.getOptionValue( this.cmdAsStr ); // CmdLineArgsBasic.BATCHCMD[1] );
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/** For making it easy to have simple code generate debugging-output, added this toString() method to this class.
*/
public String toString() {
return super.toString() +" batchFilePath="+batchFilePath;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// For unit-testing purposes only
public static void main(String[] args) {
try{
final CmdLineArgsBatchCmd cla = new CmdLineArgsBatchCmd( Enums.CmdEnum.BATCH, CmdLineArgsBasic.BATCHCMD[0], CmdLineArgsBasic.BATCHCMD[1], CmdLineArgsBasic.BATCHCMD[2], 1, "BatchFileName" ); // Note: there's a trick in the parameter-string.. as setArgName() assumes a single 'word' and puts a '<' & '>' around that single-word.
cla.define();
cla.parse(args);
System.out.println(cla);
} catch( Exception e) {
e.printStackTrace(System.err); // main() for unit-testing
System.exit(1);
}
}
}