Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Commands and Converters

Commands and Converters

Commands

Commands are contributed by implementing the CommandMarker interface. Commands are implemented by methods, so in the CommandMarker implementation, the methods that must be exposed as commands on the command line need to be annotated with the CliCommand annotation. That annotation provides the name of the command as specified on the command line along with a text that describes the command. The method arguments are then annotated with the CliOption annotation to describe the individual command line arguments for the command.

With, the CliOption annotation, the name of the command line option can be specified. These options are prefixed with --. This annotation provides other information, such as the default values or whether the option is mandatory. Providing a default value on the command line allows defining flag arguments, such as boolean, without specifying the default value. For example, you can define --logOutput instead of --logOutput true. The default unspecified value can then be set as false.
Note: Short-form command line options, commands starting with a single hyphen or containing one character, such as -c are not currently supported.
Converters

Converters are required if the method arguments are declared as custom objects or complex objects, such as properties objects. The Data Population Tool provides converters that convert string input on the command line to properties objects, Spring Resource objects, and OutputStreams . The converters are provided in the ep-dp-cli-standard-converters-plugin module.

With converters, Data Population Tool provides the conversion mechanism from string values to complex types to be provided once (DRY), and allows the command methods to declare methods using the business objects rather than String inputs.

Converters are contributed by implementing the Converter interface. The converters are implemented by two methods, Convert.supports() and Convert.convertFromText(). The Convert.supports() method specifies whether the Converter instance can convert a string to the given class, and the converter.convertFromText() converts a string taken from the command line option in to a class.

When a converter uses contexts, the annotated command method argument must be supplied with a context value in its @CliOption annotation. The context value is then passed to the Converter.supports() method when converting it. The Converter that declares a context value specifies that the Converter supports that context only. Two Converter instances converting to the same class type must not use the same context value, because both Converters are matched for conversion and which one is selected for conversion is arbitrary. The Converter declaring that context value can indicate it supports that context, and for any other context indicated it doesn't support that value. The correct Converter is then selected.