New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

com.zkejid.constructor:cli-arguments

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.zkejid.constructor:cli-arguments

Project handles command line arguments. It helps working with values passed in.

  • 1.0.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Build Status

CLI Arguments module

Constructor part for handling command line arguments.

Usage

Command line syntax

You can register two types of arguments: flags and properties. Flags are single letter arguments which represent boolean value. If given flag exists in an argument line, then it has value of true. If it does not exist, then it has value of false. Flags can be merged in one line argument. Here is the call to ls utility with two flags - -a and -l - merged together:

ls -al

Properties are name-value pairs, that user can specify in an argument line:

ls --tabsize=4

Command line can contain more arguments, than you registered. Parser would leave these arguments unparsed. We will refer to these arguments as plain arguments. You can force parser to treat the rest of command line as plain arguments if place -- argument. All arguments to the right from this argument wold be plain.

API

To use the API you should request ArgumentsFactory.class interface in your ConstructorPart implementation:

  @Override
  public Set<Class<?>> getInterfacesNecessary() {
    return Set.of(ArgumentsFactory.class);
  }

ArgumentsFactory allows you to create an instance of the parser:

final ArgumentsParser parser = argumentsFactory.createParser();

Parser holds the configuration of arguments given instance of parser could parse. You can create as many instances of parser as you wish and configure them separately.

You can create a flag with expression:

Argument all = parser.addFlag("a", "all");

You can create a property with expression:

Argument tabSize = parser.addProperty("T", "tabsize");

The Argument object serves as key for retrieval of value:

ParseResult parseResult = parser.parse(strings);
final StringValue allValue = parseResult.getArgumentsParsed().get(all);
if (allValue.getInputValueType() == InputValueType.SPECIFIED) {
  // handle --all 
}

Example

You can find an example of application built around the module in cli-arguemnts-helloworld artifact.

Constructor Module

CliArguments is the module of Constructor Framework. You can simply place artifacts of this module on the path of application to use its API.

Tests

Module API has set of tests. You can use cli-arguments-apitest artifact to test your own implementation of API. Artifact contains set of *CheckList files. These files are abstract JUnit5 test classes. You should extend the class ans provide your implementation through the abstract method.

Versioning

Artifact versions of the CliArguments Module follow the Semantic Versioning 2.0.0 specification.

License

The module is provided under MIT License Copyright (c) 2020 Zkejid.

FAQs

Package last updated on 20 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc