1 package fr.in2p3.jsaga.command;
2
3 import org.apache.commons.cli.*;
4 import org.ogf.saga.namespace.*;
5 import org.ogf.saga.session.Session;
6 import org.ogf.saga.session.SessionFactory;
7 import org.ogf.saga.url.URL;
8 import org.ogf.saga.url.URLFactory;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class NamespaceMakeDir extends AbstractCommand {
23 private static final String OPT_HELP = "h", LONGOPT_HELP = "help";
24 private static final String OPT_NOT_EXCL = "f", LONGOPT_NOT_EXCL = "force";
25 private static final String OPT_CREATEPARENTS = "p", LONGOPT_CREATEPARENTS = "parents";
26
27 public NamespaceMakeDir() {
28 super("jsaga-mkdir", new String[]{"URL"}, new String[]{OPT_HELP, LONGOPT_HELP});
29 }
30
31 public static void main(String[] args) throws Exception {
32 NamespaceMakeDir command = new NamespaceMakeDir();
33 CommandLine line = command.parse(args);
34 if (line.hasOption(OPT_HELP))
35 {
36 command.printHelpAndExit(null);
37 }
38 else
39 {
40
41 URL url = URLFactory.createURL(command.m_nonOptionValues[0]);
42 int flags =(line.hasOption(OPT_NOT_EXCL) ? Flags.NONE : Flags.EXCL)
43 .or(line.hasOption(OPT_CREATEPARENTS)
44 ? Flags.CREATE.or(Flags.CREATEPARENTS)
45 : Flags.CREATE.getValue());
46
47
48 Session session = SessionFactory.createSession(true);
49 NSDirectory dir = NSFactory.createNSDirectory(session, url, flags);
50 dir.close();
51 System.exit(0);
52 }
53 }
54
55 protected Options createOptions() {
56 Options opt = new Options();
57 opt.addOption(OptionBuilder.withDescription("Display this help and exit")
58 .withLongOpt(LONGOPT_HELP)
59 .create(OPT_HELP));
60 opt.addOption(OptionBuilder.withDescription("Do not fail if target already exist")
61 .isRequired(false)
62 .withLongOpt(LONGOPT_NOT_EXCL)
63 .create(OPT_NOT_EXCL));
64 opt.addOption(OptionBuilder.withDescription("Make parent directories as needed")
65 .isRequired(false)
66 .withLongOpt(LONGOPT_CREATEPARENTS)
67 .create(OPT_CREATEPARENTS));
68 return opt;
69 }
70 }