Updated copyright message.
[meviz.git] / src / main / java / eu / svjatoslav / meviz / Main.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012 -- 2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz;
11
12 import eu.svjatoslav.meviz.encoder.Encoder;
13
14 import java.util.ArrayList;
15
16 class Main {
17
18     private static ArrayList<Module> modules;
19
20     private static String[] getRemainingOptions(final String[] options) {
21         final String[] remainingOptions = new String[options.length - 1];
22
23         System.arraycopy(options, 1, remainingOptions, 0, options.length - 1);
24
25         return remainingOptions;
26     }
27
28     private static void initModules() {
29         modules = new ArrayList<>();
30
31         modules.add(new Encoder());
32         modules.add(new eu.svjatoslav.meviz.htmlindexer.Main());
33         modules.add(new eu.svjatoslav.meviz.renamer.Main());
34         modules.add(new eu.svjatoslav.meviz.grabmemcard.Main());
35         modules.add(new eu.svjatoslav.meviz.bomremove.Main());
36         modules.add(new eu.svjatoslav.meviz.replace.Main());
37     }
38
39     public static void main(final String[] args) throws Exception {
40
41         initModules();
42
43         if (args.length < 1)
44             showHelp();
45         else if (args[0].equals("help")) {
46             if (args.length != 2)
47                 showHelp();
48             else {
49
50                 for (final Module module : modules)
51                     if (args[1].equals(module.getModuleCommand())) {
52                         module.showCommandlineHelp();
53                         return;
54                     }
55
56                 System.out.println("Error: unrecognized module by name:"
57                         + args[1] + "\n");
58                 showHelp();
59
60             }
61         } else {
62
63             for (final Module module : modules)
64                 if (args[0].equals(module.getModuleCommand())) {
65                     module.run(getRemainingOptions(args));
66                     return;
67                 }
68
69             System.out.println("Error: unrecognized commandline option:"
70                     + args[0] + "\n");
71             showHelp();
72         }
73
74     }
75
76     private static void showHelp() {
77         final StringBuilder buffer = new StringBuilder();
78
79         buffer.append("Commandline options: \n"
80                 + "help\n    show this help screen \n\n");
81
82         buffer.append("help <module>\n    show module specific help screen\n\n");
83
84         buffer.append("Available modules:\n\n");
85
86         for (final Module module : modules) {
87             buffer.append(module.getModuleCommand() + "\n");
88             buffer.append("    " + module.getDescription() + "\n\n");
89         }
90
91         System.out.println(buffer.toString());
92     }
93 }