@@ -19,23 +19,19 @@ public final class CliArgumentParser
1919 static final int DEFAULT_LIMIT = 20 ;
2020 static final int MAX_LIMIT = 10000 ;
2121 static final int DEFAULT_TREE_DEPTH = 8 ;
22- static final int DEFAULT_AGENT_TREE_DEPTH = 4 ;
2322 static final int DEFAULT_INSPECT_OBJECT_TREE_DEPTH = 3 ;
2423
2524 public CliArguments parse (String [] args ) throws CliException
2625 {
2726 if (args == null || args .length == 0 )
28- return new CliArguments (null , null , null , null , CliArguments .OutputProfile .DEFAULT ,
29- CliArguments .OutputFormat .TEXT , false , true , DEFAULT_LIMIT , DEFAULT_TREE_DEPTH , null , null ,
30- null , null , false , null , null );
27+ return new CliArguments (null , null , null , null , CliArguments .OutputFormat .TEXT , false , true ,
28+ DEFAULT_LIMIT , DEFAULT_TREE_DEPTH , null , null , null , null , false , null , null );
3129
3230 CliCommand command = null ;
3331 CliCommand subjectCommand = null ;
3432 String subjectName = null ;
3533 File heapFile = null ;
36- CliArguments .OutputProfile profile = CliArguments .OutputProfile .DEFAULT ;
3734 CliArguments .OutputFormat format = CliArguments .OutputFormat .TEXT ;
38- boolean formatExplicit = false ;
3935 boolean verbose = false ;
4036 boolean help = false ;
4137 int limit = DEFAULT_LIMIT ;
@@ -63,25 +59,23 @@ public CliArguments parse(String[] args) throws CliException
6359 }
6460 else if ("--agent" .equals (arg )) //$NON-NLS-1$
6561 {
66- profile = CliArguments . OutputProfile . AGENT ;
62+ throw removedOption ( "--agent" ); //$NON-NLS-1$
6763 }
6864 else if (arg .startsWith ("--profile=" )) //$NON-NLS-1$
6965 {
70- profile = CliArguments . OutputProfile . parse ( arg . substring ( "--profile=" . length ()) ); //$NON-NLS-1$
66+ throw removedOption ( "--profile" ); //$NON-NLS-1$
7167 }
7268 else if ("--profile" .equals (arg )) //$NON-NLS-1$
7369 {
74- profile = CliArguments . OutputProfile . parse ( nextArg ( args , ++ ii , "--profile" ) ); //$NON-NLS-1$
70+ throw removedOption ( "--profile" ); //$NON-NLS-1$
7571 }
7672 else if (arg .startsWith ("--format=" )) //$NON-NLS-1$
7773 {
7874 format = CliArguments .OutputFormat .parse (arg .substring ("--format=" .length ())); //$NON-NLS-1$
79- formatExplicit = true ;
8075 }
8176 else if ("--format" .equals (arg )) //$NON-NLS-1$
8277 {
8378 format = CliArguments .OutputFormat .parse (nextArg (args , ++ii , "--format" )); //$NON-NLS-1$
84- formatExplicit = true ;
8579 }
8680 else if (arg .startsWith ("--limit=" )) //$NON-NLS-1$
8781 {
@@ -210,22 +204,19 @@ else if (command.requiresSnapshot() && heapFile == null)
210204 }
211205 }
212206
213- if (profile == CliArguments .OutputProfile .AGENT && !formatExplicit )
214- format = CliArguments .OutputFormat .JSON ;
215-
216207 if (command == null )
217208 {
218209 if (help )
219210 {
220- return new CliArguments (null , null , null , null , profile , format , verbose , true , limit ,
211+ return new CliArguments (null , null , null , null , format , verbose , true , limit ,
221212 treeDepthLimit , objectAddress , className , selectField , fieldPath , includeSubclasses ,
222213 oqlQuery , queryCommand );
223214 }
224215 throw CliException .usage ("Missing command" ); //$NON-NLS-1$
225216 }
226217
227218 if (!treeDepthExplicit )
228- treeDepthLimit = defaultTreeDepth (command , profile );
219+ treeDepthLimit = defaultTreeDepth (command );
229220
230221 if (command == CliCommand .OQL )
231222 oqlQuery = resolveExclusiveInput ("oql" , "--query" , oqlQuery , "--query-file" , oqlQueryFile , //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -237,53 +228,14 @@ else if (command == CliCommand.QUERY)
237228 if (!limitExplicit )
238229 limit = defaultLimit (command , queryCommand );
239230
240- CliArguments parsed = new CliArguments (command , subjectCommand , subjectName , heapFile , profile , format , verbose ,
241- help , limit , treeDepthLimit , objectAddress , className , selectField , fieldPath ,
242- includeSubclasses , oqlQuery , queryCommand );
231+ CliArguments parsed = new CliArguments (command , subjectCommand , subjectName , heapFile , format , verbose , help ,
232+ limit , treeDepthLimit , objectAddress , className , selectField , fieldPath , includeSubclasses ,
233+ oqlQuery , queryCommand );
243234 validate (parsed );
244235 return parsed ;
245236 }
246237
247- public CliArguments .OutputProfile detectProfile (String [] args )
248- {
249- if (args == null )
250- return CliArguments .OutputProfile .DEFAULT ;
251-
252- CliArguments .OutputProfile profile = CliArguments .OutputProfile .DEFAULT ;
253- for (int ii = 0 ; ii < args .length ; ii ++)
254- {
255- String arg = args [ii ];
256- if ("--agent" .equals (arg )) //$NON-NLS-1$
257- {
258- profile = CliArguments .OutputProfile .AGENT ;
259- }
260- else if (arg .startsWith ("--profile=" )) //$NON-NLS-1$
261- {
262- try
263- {
264- profile = CliArguments .OutputProfile .parse (arg .substring ("--profile=" .length ())); //$NON-NLS-1$
265- }
266- catch (CliException ignore )
267- {
268- return profile ;
269- }
270- }
271- else if ("--profile" .equals (arg ) && ii + 1 < args .length ) //$NON-NLS-1$
272- {
273- try
274- {
275- profile = CliArguments .OutputProfile .parse (args [++ii ]);
276- }
277- catch (CliException ignore )
278- {
279- return profile ;
280- }
281- }
282- }
283- return profile ;
284- }
285-
286- public CliArguments .OutputFormat detectFormat (String [] args , CliArguments .OutputProfile profile )
238+ public CliArguments .OutputFormat detectFormat (String [] args )
287239 {
288240 if (args != null )
289241 {
@@ -298,7 +250,7 @@ public CliArguments.OutputFormat detectFormat(String[] args, CliArguments.Output
298250 }
299251 catch (CliException ignore )
300252 {
301- return defaultFormat (profile );
253+ return defaultFormat ();
302254 }
303255 }
304256 else if ("--format" .equals (arg ) && ii + 1 < args .length ) //$NON-NLS-1$
@@ -309,12 +261,12 @@ else if ("--format".equals(arg) && ii + 1 < args.length) //$NON-NLS-1$
309261 }
310262 catch (CliException ignore )
311263 {
312- return defaultFormat (profile );
264+ return defaultFormat ();
313265 }
314266 }
315267 }
316268 }
317- return defaultFormat (profile );
269+ return defaultFormat ();
318270 }
319271
320272 private void validate (CliArguments arguments ) throws CliException
@@ -414,10 +366,9 @@ private String readStandardInput(String optionName) throws CliException
414366 }
415367 }
416368
417- private CliArguments .OutputFormat defaultFormat (CliArguments . OutputProfile profile )
369+ private CliArguments .OutputFormat defaultFormat ()
418370 {
419- return profile == CliArguments .OutputProfile .AGENT ? CliArguments .OutputFormat .JSON
420- : CliArguments .OutputFormat .TEXT ;
371+ return CliArguments .OutputFormat .TEXT ;
421372 }
422373
423374 private int parseLimit (String value ) throws CliException
@@ -462,8 +413,7 @@ private boolean isHelpToken(String token)
462413 return "--help" .equals (token ) || "-h" .equals (token ) || "help" .equals (token ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
463414 }
464415
465- public CliArguments partialParse (String [] args , CliArguments .OutputProfile profile ,
466- CliArguments .OutputFormat format )
416+ public CliArguments partialParse (String [] args , CliArguments .OutputFormat format )
467417 {
468418 CliCommand command = null ;
469419 CliCommand subjectCommand = null ;
@@ -477,7 +427,7 @@ public CliArguments partialParse(String[] args, CliArguments.OutputProfile profi
477427 boolean includeSubclasses = false ;
478428 String oqlQuery = null ;
479429 String queryCommand = null ;
480- int treeDepthLimit = defaultTreeDepth (null , profile );
430+ int treeDepthLimit = defaultTreeDepth (null );
481431 boolean treeDepthExplicit = false ;
482432
483433 if (args != null )
@@ -585,9 +535,9 @@ else if (command.requiresSnapshot() && heapFile == null)
585535 }
586536
587537 if (!treeDepthExplicit )
588- treeDepthLimit = defaultTreeDepth (command , profile );
538+ treeDepthLimit = defaultTreeDepth (command );
589539
590- return new CliArguments (command , subjectCommand , subjectName , heapFile , profile , format , false , help ,
540+ return new CliArguments (command , subjectCommand , subjectName , heapFile , format , false , help ,
591541 defaultLimit (command , queryCommand ), treeDepthLimit , objectAddress , className , selectField ,
592542 fieldPath , includeSubclasses , oqlQuery , queryCommand );
593543 }
@@ -619,20 +569,19 @@ private String queryIdentifier(String queryCommand)
619569
620570 private boolean expectsValue (String option )
621571 {
622- return "--profile" .equals (option ) || "--format" .equals (option ) || "--limit" .equals (option ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
623- || "--depth" .equals (option ) //$NON-NLS-1$
572+ return "--format" .equals (option ) || "--limit" .equals (option ) || "--depth" .equals (option ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
624573 || "--object" .equals (option ) || "--class" .equals (option ) //$NON-NLS-1$ //$NON-NLS-2$
625574 || "--select-field" .equals (option ) || "--field-path" .equals (option ) //$NON-NLS-1$ //$NON-NLS-2$
626575 || "--query" .equals (option ) //$NON-NLS-1$
627576 || "--query-file" .equals (option ) //$NON-NLS-1$
628577 || "--command" .equals (option ) || "--command-file" .equals (option ); //$NON-NLS-1$ //$NON-NLS-2$
629578 }
630579
631- private int defaultTreeDepth (CliCommand command , CliArguments . OutputProfile profile )
580+ private int defaultTreeDepth (CliCommand command )
632581 {
633582 if (command == CliCommand .INSPECT_OBJECT )
634583 return DEFAULT_INSPECT_OBJECT_TREE_DEPTH ;
635- return profile == CliArguments . OutputProfile . AGENT ? DEFAULT_AGENT_TREE_DEPTH : DEFAULT_TREE_DEPTH ;
584+ return DEFAULT_TREE_DEPTH ;
636585 }
637586
638587 private boolean hasEmptyPathSegment (String fieldPath )
@@ -651,4 +600,9 @@ private int safePartialDepth(String value, int fallback)
651600 return fallback ;
652601 }
653602 }
603+
604+ private CliException removedOption (String option )
605+ {
606+ return CliException .usage (option + " has been removed. Use --format json." ); //$NON-NLS-1$
607+ }
654608}
0 commit comments