Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: standalone application #15

Merged
merged 34 commits into from
Feb 25, 2019
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c39ae6e
initial
Oct 12, 2018
496840e
working
Oct 13, 2018
0c6717a
wip
Oct 14, 2018
5a03cf5
Merge remote-tracking branch 'origin/master' into feature/standalone
Nov 22, 2018
8714161
wip: arg parser
Nov 22, 2018
fa9afb3
Merge remote-tracking branch 'origin/master' into feature/standalone
erdos Dec 16, 2018
150faec
asd
erdos Dec 16, 2018
1876b98
sad
erdos Dec 16, 2018
99571c0
wip
erdos Jan 1, 2019
bd64b65
wip
erdos Feb 18, 2019
64eeb29
more unit tests
erdos Feb 20, 2019
6e73981
wip: standalone appl
erdos Feb 23, 2019
a307863
wi
erdos Feb 23, 2019
fc7ae2b
output file path fix
erdos Feb 24, 2019
bf2e302
added simple json parser
erdos Feb 25, 2019
205636c
tests for scalars
erdos Feb 25, 2019
2720501
json parser: add map reading
erdos Feb 25, 2019
1af066c
set buf size
erdos Feb 25, 2019
75079bf
shutdown agents after main
erdos Feb 25, 2019
72ab921
added tests
erdos Feb 25, 2019
08c30fb
Merge branch 'master' into feature/standalone
erdos Feb 25, 2019
7ffd344
improvements
erdos Feb 25, 2019
346cbdc
rm unnec ws
erdos Feb 25, 2019
c9f2a7f
rm unnec frmt
erdos Feb 25, 2019
e5d8f2a
standalone: add flag to overwrite existing files
erdos Feb 25, 2019
35e8570
wip
erdos Feb 25, 2019
bbbb8c0
cleanup beforemerge
erdos Feb 25, 2019
2cc4e6c
started writing docs
erdos Feb 25, 2019
3612b7b
wip: docs
erdos Feb 25, 2019
262f366
added jobs param
erdos Feb 25, 2019
e5a5114
jobs file support
erdos Feb 25, 2019
df01676
final
erdos Feb 25, 2019
7379523
asd
erdos Feb 25, 2019
53b9b58
try-fin
erdos Feb 25, 2019
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
erdos committed Jan 1, 2019
commit 99571c08893b618aaa4f3fbee0fce9bb4cfaa586
51 changes: 42 additions & 9 deletions java-src/io/github/erdos/stencil/standalone/ArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

public class ArgsParser {

private final Set<ParamMarker> markers = new HashSet<>();

public <T> ParamMarker<T> addParam(char shortForm, String longForm, String description, Function<String, T> parser) {

final ParamMarker<T> added = new ParamMarker<>(parser, shortForm, longForm, description);
markers.add(added);
return added;
}

public ParseResult parse(String... args) {


final Map<String, String> result = new HashMap<>();
final Map<Character, String> result = new HashMap<>();
final List<String> restArgs = new ArrayList<>(args.length);

for (int i = 0; i < args.length; i++) {
Expand All @@ -34,6 +37,12 @@ public ParseResult parse(String... args) {
final String[] parts = item.split("=", 2);
final String argName = parts[0];
final String argValue = parts[1];

if (item.startsWith("--")) {
// long form
} else {
// short form
}
// TODO: do parsing here!

} else {
Expand Down Expand Up @@ -75,11 +84,11 @@ public ParamMarker<Boolean> addFlagOption(char shortName, String longName, Strin
});
}

public final class ParseResult {
private final Map<String, String> args;
public static final class ParseResult {
private final Map<Character, String> args;
private final List<String> varargs;

private ParseResult(Map<String, String> args, List<String> varargs) {
private ParseResult(Map<Character, String> args, List<String> varargs) {
this.args = unmodifiableMap(args);
this.varargs = unmodifiableList(varargs);
}
Expand All @@ -91,7 +100,7 @@ public List<String> getRestArgs() {


public <T> Optional<T> getParamValue(ParamMarker<T> marker) {
final String shortName = marker.getShortName();
final char shortName = marker.getShortForm();
if (args.containsKey(shortName)) {
final String argValue = args.get(shortName);
return Optional.of(marker.parse(argValue));
Expand All @@ -101,9 +110,33 @@ public <T> Optional<T> getParamValue(ParamMarker<T> marker) {
}
}

public interface ParamMarker<T> {
String getShortName();
private static final class ParamMarker<T> {
private final Function<String, T> parse;
private final char shortForm;
private final String longName;
private final String description;

private ParamMarker(Function<String, T> parse, char shortForm, String longName, String description) {
this.parse = parse;
this.shortForm = shortForm;
this.longName = longName;
this.description = description;
}

char getShortForm() {
return shortForm;
}

T parse(String input) {
return parse.apply(input);
}

T parse(String input);
public String getLongName() {
return longName;
}

public String getDescription() {
return description;
}
}
}