2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
20
import java.io.BufferedReader;
21
import java.io.InputStreamReader;
22
import java.util.Collection;
23
import java.util.Arrays;
24
import java.lang.reflect.Method;
27
public final class Main {
28
private static final Collection QUIT_COMMANDS =
29
Arrays.asList(new String[] {"quit", "q", "exit"});
30
private static final Collection HELP_COMMANDS =
31
Arrays.asList(new String[] {"help", "h", "?"});
33
public static void main(String[] a) throws Exception {
34
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
36
System.out.print("> ");
37
String command = in.readLine().trim();
38
if (QUIT_COMMANDS.contains(command)) {
41
if (HELP_COMMANDS.contains(command)) {
45
String[] split = command.split(" ");
46
if (split.length == 0) {
52
String[] args = new String[split.length - 1];
53
System.arraycopy(split, 1, args, 0, args.length);
54
Class cl = Class.forName(split[0] + ".Main");
55
Method m = cl.getMethod("main", new Class[] {String[].class});
56
m.invoke(null, new Object[] {args});
57
} catch (Exception ex) {
64
private static void help() {
65
System.out.println("available commands:");
66
System.out.println("\tquit: quit the console");
67
System.out.println("\thelp: displays this message");
68
System.out.println("\tlist -dir <dir>: list files in given directory");
69
System.out.println("\tfind -dir <dir> -name <name>: list files with given name in given dir");
70
System.out.println("\tsizewhere -dir <dir> -name <name>: "
71
+ "compute total size of files with given name in given dir");
72
System.out.println("\thelp: displays this message");
75
private static void error(String command) {
76
System.out.println("unknown command " + command);
77
System.out.println("type ? for help");