1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam- Initial API and implementation
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tracing
.rcp
.ui
.cli
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.linuxtools
.internal
.tracing
.rcp
.ui
.messages
.Messages
;
23 * @author Matthew Khouzam
25 public class CliParser
{
27 private static final String NOUI_ARG
= "--NOUI"; //$NON-NLS-1$
29 private static final String OPEN_ARG
= "--open"; //$NON-NLS-1$
31 private final Map
<String
, String
> params
= new HashMap
<>();
34 public static final String OPEN_FILE_LOCATION
= ".,-=open=-,."; //$NON-NLS-1$
36 public static final String NO_UI
= ".,-=noui=-,."; //$NON-NLS-1$
42 * the command line arguments
43 * @throws TracingRCPCliException
44 * an error occurred parsing the cli
46 public CliParser(final String
[] args
) throws TracingRCPCliException
{
47 for (int i
= 0; i
< args
.length
; i
++) {
48 if (args
[i
].equals(OPEN_ARG
)) {
49 put(OPEN_FILE_LOCATION
, args
, i
);
50 // skip since we have two args
53 else if (args
[i
].equals(NOUI_ARG
)) {
54 params
.put(NO_UI
, new String());
59 private void put(String key
, String
[] args
, int pos
) throws TracingRCPCliException
{
60 if (args
.length
<= pos
) {
61 throw new TracingRCPCliException(Messages
.CliParser_MalformedCommand
+ ':' + ' ' + args
[pos
]);
63 params
.put(key
, args
[pos
+ 1]);
67 * Get a parameter from the parsed command line
68 * @param key OPEN_FILE_LOCATION or NO_UI
69 * @return the value of the parameter, can be null
71 public String
getArgument(String key
) {
72 return params
.get(key
);