@@ -83,9 +83,9 @@ public static void main(String[] argv) {
83
83
OptionSet args = parseArguments (argv );
84
84
setupLogging (args );
85
85
86
- if (isVerbose ) {
86
+ if (args . has ( OPT_VERBOSE ) || args . has ( OPT_VERSION ) ) {
87
87
System .out .println ("# " + String .join (" " , System .getenv ().entrySet ().stream ().filter (e -> e .getKey ().startsWith ("GP_" )).map (e -> String .format ("%s=%s" , e .getKey (), e .getValue ())).collect (Collectors .toList ())));
88
- System .out .println ("# " + String .join (" " , argv ));
88
+ System .out .println ("# gp " + String .join (" " , argv ));
89
89
}
90
90
TerminalFactory tf = TerminalManager .getTerminalFactory ();
91
91
String reader = args .valueOf (OPT_READER );
@@ -105,7 +105,7 @@ public static void main(String[] argv) {
105
105
System .err .println ("Error: " + e .getMessage ());
106
106
e .printStackTrace ();
107
107
} finally {
108
- if (c != null ) {
108
+ if (c != null ) {
109
109
try {
110
110
c .disconnect (true );
111
111
} catch (CardException e ) {
@@ -116,6 +116,12 @@ public static void main(String[] argv) {
116
116
System .exit (ret );
117
117
}
118
118
119
+ static boolean onlyHasArg (OptionSet args , OptionSpec <?> s ) {
120
+ long needle = args .specs ().stream ().filter (e -> args .has (e )).count ();
121
+ long hay = args .specs ().stream ().filter (e -> args .has (e ) && e != s ).count ();
122
+ return needle == 1 && hay == 0 ;
123
+ }
124
+
119
125
// For running in apdu4j mode
120
126
public int run (BIBO bibo , String [] argv ) {
121
127
try {
@@ -136,6 +142,8 @@ public int run(BIBO bibo, String[] argv) {
136
142
if (Cipher .getMaxAllowedKeyLength ("AES" ) == 128 ) {
137
143
System .err .println ("Unlimited crypto policy is NOT installed!" );
138
144
}
145
+ if (onlyHasArg (args , OPT_VERSION ))
146
+ return 0 ;
139
147
}
140
148
141
149
// Load a CAP file, if specified
@@ -155,11 +163,6 @@ public int run(BIBO bibo, String[] argv) {
155
163
}
156
164
}
157
165
158
- if (args .has (OPT_LIST_PRIVS )) {
159
- System .out .println ("# Known privileges:" );
160
- System .out .println (Arrays .asList (Privilege .values ()).stream ().map (i -> i .toString ()).collect (Collectors .joining ("\n " )));
161
- }
162
-
163
166
// Now actually talk to possible terminals
164
167
APDUBIBO channel = new APDUBIBO (bibo );
165
168
// Send all raw APDU-s to the default-selected application of the card
@@ -764,7 +767,7 @@ private static Privileges getInstPrivs(OptionSet args) {
764
767
Privileges privs = new Privileges ();
765
768
if (args .has (OPT_PRIVS )) {
766
769
for (String s : args .valueOf (OPT_PRIVS ).split ("," ))
767
- privs .add (Privilege .lookup (s .trim ()).orElseThrow (() -> new IllegalArgumentException ("Unknown privilege: " + s .trim ())));
770
+ privs .add (Privilege .lookup (s .trim ()).orElseThrow (() -> new IllegalArgumentException ("Unknown privilege: " + s .trim () + " \n Valid values are: " + Arrays . asList ( Privilege . values ()). stream (). map ( i -> i . toString ()). collect ( Collectors . joining ( ", " )) )));
768
771
}
769
772
return privs ;
770
773
}
@@ -806,6 +809,7 @@ private static boolean needsAuthentication(OptionSet args) {
806
809
return Arrays .stream (yes ).anyMatch (args ::has );
807
810
}
808
811
812
+ // FIXME: replace with IllegalArgumentException
809
813
public static void fail (String msg ) {
810
814
System .err .println (msg );
811
815
System .exit (1 );
0 commit comments