Simple, small, native library for:
- Detects OS, ARCH with SystemUtil. (see OsTypes, Arch, ArchType)
- Running commands using the Terminal
- Reading arguments with CommandLineReader Command-line-util to get easy access to command line unix/windows - simple and native without any dependencies. For more professional you can use plexus-utils commons-cli
<dependency>
<groupId>berlin.yuna</groupId>
<artifactId>command-line-util</artifactId>
<version>1.0.0</version>
</dependency>
public class ArgumentParserTest {
public void parseArgsTest() {
//false == without environment variables
final ArgumentReader args = parseArgs(false, "mvn clean install --Dencoding=\"UTF-8\" --javaVersion 8 -v=true --args=1,2,3", "--args=4,5");
args.size(); // = 4
args.getCommands(); // = 3
args.hasCommand("install"); // = true
//ARGUMENTS & TYPES
args.getString("Dencoding"); // = "UTF-8"
args.getBoolean("v"); // = true
args.getLong("javaVersion"); // = 8
args.getDouble("javaVersion"); // = 8.0
//ARGUMENTS & SPLITTING & INDEXING
args.getLong("-", 1, "Dencoding"); // = 8
//DUPLICATES & LISTING & INDEXING
args.getString("args"); // = "1,2,3"
args.getString(1, "args"); // = "4,5"
args.getStrings(',', "args"); // = ["1","2","3","4","5"]
args.getLongs(',', "args"); // = [1,2,3,4,5]
validateReadmeExample(args);
}
}
new Terminal()
.consumerInfo(System.out::println) //optional listener [Consumer<String>]
.consumerError(System.err::println) //optional listener [Consumer<String>]
.consoleInfo() //optional returns all info output in a String
.consoleError() //optional returns all error output in a String
.clearConsole() //optional clears previous consoleInfo/consoleError console
.dir("myWorinkDirectory") //optional sets default working directory
.timeoutMs(512) //optional to limit command or for workaround when commands are too fast to return exit status
.breakOnError(false) //optional - only with timeoutMs possible
.execute("echo Howdy") //executes the command
.process //optional returns java Process;
//Enum [ARM, LINUX, MAC, WINDOWS, SOLARIS, UNKNOWN]
OperatingSystem os = SystemUtil.getOsType();
//Kill process
killProcessByName("tomcat");
//Translates and saves [PosixFilePermission]s to generic
SystemUtil.setFilePermissions(file, OWNER_READ, OWNER_WRITE, OWNER_EXECUTE);
//Read file (tries every charset)
String content SystemUtil.readFile(path);
List<String> contentLines SystemUtil.readFileLines(path);
//Delete dir recursively
boolean removed = SystemUtil.deleteDirectory
- Timeout test
- waitFor - some commands are too fast to get the exit status - workaround is to run terminal with .timeout().execute