Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theprez/jcmdutils
Small Utilities for helping build Java command line programs
https://github.com/theprez/jcmdutils
Last synced: 1 day ago
JSON representation
Small Utilities for helping build Java command line programs
- Host: GitHub
- URL: https://github.com/theprez/jcmdutils
- Owner: ThePrez
- License: apache-2.0
- Created: 2021-11-22T15:11:32.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-06T23:36:32.000Z (almost 3 years ago)
- Last Synced: 2023-10-15T10:08:39.376Z (over 1 year ago)
- Language: Java
- Size: 62.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JCmdUtils
Small Utilities for helping build Java command line programs## Functionality
The helper classes in this module can be summarized as providing the following high-level function:
- Make it easier to ask the user questions (or ask for passwords)
- Provide a primitive logging mechanism (though log4j is likely a better choice for nontrivial applications)
- Provide an interface that makes it easy to handle which output is shown and which is hidden when running in verbose mode (many command line utilities have a `-v`, for instance)
- Provide colorization (red, green, yellow) when the terminal supports it.
- Make it easier to call processes and handle output
- Do simple string manipulation/checking that is commonly needed for command line programs### AppLogger
Instantiate a logger instance via the `getSingleton()` method. Upon first invocation of this method,
it is determined whether the global singleton object is running in verbose mode.
```java
final AppLogger logger = AppLogger.getSingleton(isVerbose);
```
From there, you can use the `print` functions to provide colorized output to the user
```java
// This will print in red text to standard error
logger.printfln_err("Uh oh! The object '%s' does not exist", objectName);
// This will print in yellow text to standard out
logger.printfln_warn("Warning: duplicate entries exist: '%s' and '%s'", objectName, objectName2);
// This will print in default color to standard out
logger.println("Proceeding to step 2...");
// This will print in green text to standard out
logger.println_success("SUCCESS!!");
```
To do something similar, but to only show the output in verbose mode, use the `_verbose` variants.
If not running in verbose mode, the output will not be shown.
```java
// This will print in red text to standard error only if running in verbose mode
logger.printfln_err_verbose("Uh oh! The object '%s' does not exist", objectName);
// This will print in yellow text to standard out only if running in verbose mode
logger.printfln_warn_verbose("Warning: duplicate entries exist: '%s' and '%s'", objectName, objectName2);
// This will print in default color to standard out only if running in verbose mode
logger.println_verbose("Proceeding to step 2...");
// This will print in default color to standard out only if running in verbose mode
logger.println_verbose("SUCCESS!!");
```### ConsoleQuestionAsker
### ProcessLauncher
### StringUtils