Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions graphwalker-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.graphwalker/graphwalker-cli/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.graphwalker/graphwalker-cli)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.graphwalker/graphwalker-cli/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.graphwalker/graphwalker-cli)
GraphWalker CLI
===================
===============

======
Documentation at http://graphwalker.org/docs/command_line_syntax
Documentation at https://github.com/GraphWalker/graphwalker-project/wiki/Command-Line-Tool

## How to build the standalone jar of graphwalker-cli

### How to build the standalone jar of graphwalker-cli
```bash
git clone https://github.com/GraphWalker/graphwalker-project.git
cd graphwalker-project
mvn package -pl graphwalker-cli -am
```

The jar is in:
The jar is in: `graphwalker-cli/target/graphwalker-cli-<VERSION>.jar`.

Run it like:

```bash
graphwalker-cli/target/graphwalker-cli-3.2.1.jar
java -jar graphwalker-cli/target/graphwalker-cli-<VERSION>.jar
```

128 changes: 44 additions & 84 deletions graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -116,106 +116,66 @@ public static void main(String[] args) {
private void run(String[] args) {
Options options = new Options();
JCommander jc = new JCommander(options);
jc.setProgramName("java -jar graphwalker.jar");
try {
jc.parseWithoutValidation(args);
} catch (Exception e) {
// ignore
}
jc.setProgramName("graphwalker");

try {
setLogLevel(options);
offline = new Offline();
jc.addCommand("offline", offline);

if (options.help) {
options = new Options();
jc = new JCommander(options);
offline = new Offline();
jc.addCommand("offline", offline);
online = new Online();
jc.addCommand("online", online);

online = new Online();
jc.addCommand("online", online);
methods = new Methods();
jc.addCommand("methods", methods);

methods = new Methods();
jc.addCommand("methods", methods);
requirements = new Requirements();
jc.addCommand("requirements", requirements);

requirements = new Requirements();
jc.addCommand("requirements", requirements);
convert = new Convert();
jc.addCommand("convert", convert);

convert = new Convert();
jc.addCommand("convert", convert);
source = new Source();
jc.addCommand("source", source);

source = new Source();
jc.addCommand("source", source);
check = new Check();
jc.addCommand("check", check);

check = new Check();
jc.addCommand("check", check);
try {
jc.parse(args);
setLogLevel(options);

jc.parse(args);
if (options.help) {
jc.usage();
return;
} else if (options.version) {
System.out.println(printVersionInformation());
return;
} else if (jc.getParsedCommand() == null) {
throw new MissingCommandException("Missing a command. Add '--help'");
}

// Need to instantiate options again to avoid
// ParameterException "Can only specify option --debug once."
options = new Options();
jc = new JCommander(options);
offline = new Offline();
jc.addCommand("offline", offline);

online = new Online();
jc.addCommand("online", online);

methods = new Methods();
jc.addCommand("methods", methods);

requirements = new Requirements();
jc.addCommand("requirements", requirements);

convert = new Convert();
jc.addCommand("convert", convert);

source = new Source();
jc.addCommand("source", source);

check = new Check();
jc.addCommand("check", check);

jc.parse(args);

// Parse for commands
if (jc.getParsedCommand() != null) {
if (jc.getParsedCommand().equalsIgnoreCase("offline")) {
command = Command.OFFLINE;
runCommandOffline();
} else if (jc.getParsedCommand().equalsIgnoreCase("online")) {
command = Command.ONLINE;
runCommandOnline();
} else if (jc.getParsedCommand().equalsIgnoreCase("methods")) {
command = Command.METHODS;
runCommandMethods();
} else if (jc.getParsedCommand().equalsIgnoreCase("requirements")) {
command = Command.REQUIREMENTS;
runCommandRequirements();
} else if (jc.getParsedCommand().equalsIgnoreCase("convert")) {
command = Command.CONVERT;
runCommandConvert();
} else if (jc.getParsedCommand().equalsIgnoreCase("source")) {
command = Command.SOURCE;
runCommandSource();
} else if (jc.getParsedCommand().equalsIgnoreCase("check")) {
command = Command.SOURCE;
runCommandCheck();
}
}

// No commands or options were found
else {
throw new MissingCommandException("Missing a command. Add '--help'");
if (jc.getParsedCommand().equalsIgnoreCase("offline")) {
command = Command.OFFLINE;
runCommandOffline();
} else if (jc.getParsedCommand().equalsIgnoreCase("online")) {
command = Command.ONLINE;
runCommandOnline();
} else if (jc.getParsedCommand().equalsIgnoreCase("methods")) {
command = Command.METHODS;
runCommandMethods();
} else if (jc.getParsedCommand().equalsIgnoreCase("requirements")) {
command = Command.REQUIREMENTS;
runCommandRequirements();
} else if (jc.getParsedCommand().equalsIgnoreCase("convert")) {
command = Command.CONVERT;
runCommandConvert();
} else if (jc.getParsedCommand().equalsIgnoreCase("source")) {
command = Command.SOURCE;
runCommandSource();
} else if (jc.getParsedCommand().equalsIgnoreCase("check")) {
command = Command.CHECK;
runCommandCheck();
}

} catch (UnsupportedFileFormat | MissingCommandException e) {
System.err.println(e.getMessage() + System.lineSeparator());
} catch (ParameterException e) {
Expand Down
10 changes: 5 additions & 5 deletions graphwalker-cli/src/main/java/org/graphwalker/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -30,12 +30,12 @@

public class Options {

@Parameter(names = {"--help", "-h"}, description = "Prints help text")
@Parameter(names = {"--help", "-h"}, help = true, description = "Show this message and exit.")
public boolean help = false;

@Parameter(names = {"--version", "-v"}, description = "Prints the version of graphwalker")
@Parameter(names = {"--version", "-v"}, help = true, description = "Show the graphwalker version and exit.")
public boolean version = false;

@Parameter(names = {"--debug", "-d"}, description = "Sets the log level: OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL. Default is OFF")
@Parameter(names = {"--debug", "-d"}, description = "Sets the log level. Valid log levels are: OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL.")
public String debug = "OFF";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,15 +31,18 @@
import java.util.ArrayList;
import java.util.List;

@Parameters(commandDescription = "Check and analyze model(s) for issues. See http://graphwalker.org/docs/command_line_syntax")
@Parameters(commandDescription = "Check and analyze model(s) for issues.")
public class Check {

@Parameter(names = {"--model", "-m"}, required = true, arity = 2,
description = "Model followed by generator with stop condition. " +
"The format is GENERATOR(STOP_CONDITION) See http://graphwalker.org/docs/path_generators_and_stop_conditions")
@Parameter(names = {"--model", "-m"}, required = false, arity = 2,
description = "The model(s), as a GRAPHML or JSON file followed by generator with stop condition. " +
"The format is GENERATOR(STOP_CONDITION) (e.g \"random(never)\", \"weighted_random(length(24))\"). " +
"This option can occur multiple times.")
public List<String> model = new ArrayList<>();

@Parameter(names = {"--blocked",
"-b"}, arity = 1, description = "This option enables or disables the BLOCKED feature. When \"-b true\" GraphWalker will filter out elements in models with the keyword BLOCKED. When \"-b false\" GraphWalker will not filter out any elements in models with the keyword BLOCKED.")
@Parameter(names = {"--blocked", "-b"}, arity = 1,
description = "This option enables or disables the BLOCKED feature. " +
"When \"-b true\" GraphWalker will filter out any elements with the keyword BLOCKED. " +
"When \"-b false\" GraphWalker will not filter out elements with the keyword BLOCKED.")
public boolean blocked = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -30,19 +30,20 @@
import com.beust.jcommander.Parameters;
import org.graphwalker.io.factory.ContextFactoryScanner;

@Parameters(commandDescription = "Convert a graph in file format, to some other format. See http://graphwalker.org/docs/command_line_syntax")
@Parameters(commandDescription = "Convert a graph from one format, to some other format.")
public class Convert {

@Parameter(names = {"--input", "-i"}, required = true, arity = 1,
description = "This command requires an input file." +
"See http://graphwalker.org/docs/command_line_syntax")
description = "The input model file.")
public String input = "";

@Parameter(names = {"--format", "-f"}, required = false, arity = 1,
description = "Which format to convert into. Valid key words are: JSON [default], GRAPHML, DOT or JAVA")
description = "Which format to convert into. Valid key words are: JSON [default], GRAPHML, DOT or JAVA.")
public String format = ContextFactoryScanner.JSON;

@Parameter(names = {"--blocked",
"-b"}, arity = 1, description = "This option enables or disables the BLOCKED feature. When \"-b true\" GraphWalker will filter out elements in models with the keyword BLOCKED. When \"-b false\" GraphWalker will not filter out any elements in models with the keyword BLOCKED.")
@Parameter(names = {"--blocked", "-b"}, arity = 1,
description = "This option enables or disables the BLOCKED feature. " +
"When \"-b true\" GraphWalker will filter out any elements with the keyword BLOCKED. " +
"When \"-b false\" GraphWalker will not filter out elements with the keyword BLOCKED.")
public boolean blocked = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,14 +31,16 @@
import java.util.ArrayList;
import java.util.List;

@Parameters(commandDescription = "Generates a list of unique names of vertices and edges in the model. See http://graphwalker.org/docs/command_line_syntax")
@Parameters(commandDescription = "Generates a list of unique names of vertices and edges in the model.")
public class Methods {

@Parameter(names = {"--model", "-m"}, required = true,
description = "The model(s)")
description = "The model(s), as a GRAPHML or JSON file. This option can occur multiple times.")
public List<String> model = new ArrayList<>();

@Parameter(names = {"--blocked",
"-b"}, arity = 1, description = "This option enables or disables the BLOCKED feature. When \"-b true\" GraphWalker will filter out elements in models with the keyword BLOCKED. When \"-b false\" GraphWalker will not filter out any elements in models with the keyword BLOCKED.")
@Parameter(names = {"--blocked", "-b"}, arity = 1,
description = "This option enables or disables the BLOCKED feature. " +
"When \"-b true\" GraphWalker will filter out any elements with the keyword BLOCKED. " +
"When \"-b false\" GraphWalker will not filter out elements with the keyword BLOCKED.")
public boolean blocked = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,35 +31,38 @@
import java.util.ArrayList;
import java.util.List;

@Parameters(commandDescription = "Generate a test sequence offline. The sequence is printed to the standard output. See http://graphwalker.org/docs/command_line_syntax")
@Parameters(commandDescription = "Offline means generating a test sequence that can later be run automatically. The sequence is printed to the standard output.")
public class Offline {

@Parameter(names = {"--verbose", "-o"}, required = false,
description = "Will print more details to stdout")
description = "Will print more details to stdout.")
public boolean verbose = false;

@Parameter(names = {"--unvisited", "-u"}, required = false,
description = "Will also print the remaining unvisited elements in the model.")
public boolean unvisited = false;

@Parameter(names = {"--model", "-m"}, required = false, arity = 2,
description = "The model, as a graphml file followed by generator with stop condition. " +
"The format is GENERATOR(STOP_CONDITION) See http://graphwalker.org/docs/path_generators_and_stop_conditions")
description = "The model(s), as a GRAPHML or JSON file followed by generator with stop condition. " +
"The format is GENERATOR(STOP_CONDITION) (e.g \"random(never)\", \"weighted_random(length(24))\"). " +
"This option can occur multiple times.")
public List<String> model = new ArrayList<>();

@Parameter(names = {"--gw3", "-g"}, required = false, arity = 1,
description = "The model, as a single gw3 file")
description = "The model, as a single gw3 file.")
public String gw3 = "";

@Parameter(names = {"--start-element", "-e"}, required = false,
description = "Sets the starting element in the [first] model.")
public String startElement = "";

@Parameter(names = {"--blocked",
"-b"}, arity = 1, description = "This option enables or disables the BLOCKED feature. When \"-b true\" GraphWalker will filter out elements in models with the keyword BLOCKED. When \"-b false\" GraphWalker will not filter out any elements in models with the keyword BLOCKED.")
@Parameter(names = {"--blocked", "-b"}, arity = 1,
description = "This option enables or disables the BLOCKED feature. " +
"When \"-b true\" GraphWalker will filter out any elements with the keyword BLOCKED. " +
"When \"-b false\" GraphWalker will not filter out elements with the keyword BLOCKED.")
public boolean blocked = true;

@Parameter(names = {"--seed", "-d"}, required = false,
description = "Seed the random generator using the provided number.")
description = "Seed the random generator using the provided number. Using a seeded number, will generate the same path every time.")
public long seed = 0;
}
Loading