]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.core/src/org/argeo/sync/cli/Sync.java
Merge branch 'master' of https://code.argeo.org/git/apache2/argeo-commons.git
[lgpl/argeo-commons.git] / org.argeo.core / src / org / argeo / sync / cli / Sync.java
1 package org.argeo.sync.cli;
2
3 import java.net.URI;
4 import java.nio.file.Paths;
5 import java.util.List;
6
7 import org.apache.commons.cli.CommandLine;
8 import org.apache.commons.cli.CommandLineParser;
9 import org.apache.commons.cli.DefaultParser;
10 import org.apache.commons.cli.HelpFormatter;
11 import org.apache.commons.cli.Option;
12 import org.apache.commons.cli.Options;
13 import org.argeo.sync.fs.PathSync;
14
15 public class Sync {
16
17 public static void main(String[] args) {
18 Options options = new Options();
19 options.addOption("r", "recursive", false, "recurse into directories");
20 options.addOption(Option.builder().longOpt("progress").hasArg(false).desc("show progress").build());
21
22 CommandLineParser parser = new DefaultParser();
23 try {
24 CommandLine line = parser.parse(options, args);
25 List<String> remaining = line.getArgList();
26 if (remaining.size() == 0) {
27 System.err.println("There must be at least one argument");
28 printHelp(options);
29 System.exit(1);
30 }
31 URI sourceUri = new URI(remaining.get(0));
32 URI targetUri;
33 if (remaining.size() == 1) {
34 targetUri = Paths.get(System.getProperty("user.dir")).toUri();
35 } else {
36 targetUri = new URI(remaining.get(1));
37 }
38 PathSync pathSync = new PathSync(sourceUri, targetUri);
39 pathSync.run();
40 } catch (Exception exp) {
41 exp.printStackTrace();
42 printHelp(options);
43 System.exit(1);
44 }
45 }
46
47 public static void printHelp(Options options) {
48 HelpFormatter formatter = new HelpFormatter();
49 formatter.printHelp("sync SRC [DEST]", options, true);
50 }
51
52 }