1 package be
.nikiroo
.gofetch
;
4 import java
.io
.IOException
;
6 import be
.nikiroo
.gofetch
.support
.BasicSupport
.Type
;
9 * This class is tha main entry point of the program. It will parse the
10 * arguments, checks them (and warn-and-exit if they are invalid) then call
11 * {@link Fetcher#start()}.
20 * save-to-dir selector-subdir type max hostname port
23 * in case of I/O error
25 public static void main(String
[] args
) throws IOException
{
26 if (args
.length
< 6) {
28 .println("Syntax error: gofecth [target dir] [selector] [type or 'ALL'] [max stories] [hostname] [port]");
32 String dirStr
= args
[0];
33 String preselectorStr
= args
[1];
34 String typeStr
= args
[2];
35 String maxStoriesStr
= args
[3];
36 String hostnameStr
= args
[4];
37 String portStr
= args
[5];
40 File dir
= new File(dirStr
);
44 System
.err
.println("Cannot open/create the root directory: "
51 .println("Root directory exists and is a file: " + dirStr
);
57 // - DO NOT end with /
58 // - always starts with / if not empty
59 String preselector
= "";
60 if (preselectorStr
!= null && !preselectorStr
.startsWith("/")) {
61 preselector
= "/" + preselectorStr
;
63 while (preselector
.endsWith("/")) {
64 preselector
= preselector
.substring(0, preselector
.length() - 1);
69 if (!"ALL".equals(typeStr
)) {
71 type
= Type
.valueOf(typeStr
.toUpperCase());
72 } catch (IllegalArgumentException e
) {
73 System
.err
.println("Invalid type: " + typeStr
);
78 // Max number of stories to display in the cache
81 maxStories
= Integer
.parseInt(maxStoriesStr
);
82 } catch (NumberFormatException e
) {
84 .println("The maximum number of stories cannot be parsed: "
90 String hostname
= hostnameStr
;
95 port
= Integer
.parseInt(portStr
);
96 } catch (NumberFormatException e
) {
97 System
.err
.println("The port cannot be parsed: " + portStr
);
101 if (port
< 0 || port
> 65535) {
102 System
.err
.println("Invalid port number: " + portStr
);
106 new Fetcher(dir
, preselector
, type
, maxStories
, hostname
, port
).start();