All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jio.console.JsObjConsoleCommand Maven / Gradle / Ivy

There is a newer version: 3.0.0-RC2
Show newest version
package jio.console;

import jio.IO;
import jsonvalues.JsObj;
import jsonvalues.JsPath;
import jsonvalues.Json;

import java.util.function.Function;

/**
 * Class to create different commands to execute interactive programs that allow the user to compose a JSON given a
 * provided spec. The constructor takes three arguments: the command name and description, and the program that
 * interacts with the user to compose the JSON. To execute the command:
 *
 * 
 *     json command_name
 * 
*

* To get some help about the program and show the description: *

 *     help json command_name
 * 
* * @see JsObjConsole */ public class JsObjConsoleCommand extends Command { private static final String COMMAND_NAME = "json-console"; private final JsConsole> program; /** * Constructor to create a JsObjConsoleCommand. * * @param name the name of the command * @param description the description (will show up if the user types in the help command) * @param objConsole the program that composes the JSON * @see JsObjConsole */ public JsObjConsoleCommand(final String name, final String description, final JsObjConsole objConsole ) { super(String.format("%s %s", COMMAND_NAME, name), description, tokens -> tokens.length == 2 && tokens[0].equalsIgnoreCase(COMMAND_NAME) && tokens[1].equalsIgnoreCase(name)); this.program = objConsole; } @Override public Function> apply(final JsObj conf, final State state ) { return tokens -> program.apply(JsPath.empty()) .map(Json::toPrettyString); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy