Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / source / ch / cyberduck / cli / TerminalHelpPrinter.java
blobf654156c05deb06ac2e5fbfa751078122f3a85cc
1 package ch.cyberduck.cli;
3 /*
4 * Copyright (c) 2002-2014 David Kocher. All rights reserved.
5 * http://cyberduck.io/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.io
21 import ch.cyberduck.core.Local;
22 import ch.cyberduck.core.LocalFactory;
23 import ch.cyberduck.core.Protocol;
24 import ch.cyberduck.core.ProtocolFactory;
25 import ch.cyberduck.core.aquaticprime.License;
26 import ch.cyberduck.core.aquaticprime.LicenseFactory;
27 import ch.cyberduck.core.preferences.Preferences;
28 import ch.cyberduck.core.preferences.PreferencesFactory;
30 import org.apache.commons.cli.HelpFormatter;
31 import org.apache.commons.cli.Options;
32 import org.apache.commons.lang3.StringUtils;
34 import java.text.MessageFormat;
36 /**
37 * @version $Id$
39 public final class TerminalHelpPrinter {
41 private TerminalHelpPrinter() {
45 public static void print(final Options options) {
46 print(options, new TerminalHelpFormatter());
49 public static void print(final Options options, final HelpFormatter formatter) {
50 formatter.setSyntaxPrefix("Usage:");
51 final StringBuilder protocols = new StringBuilder(StringUtils.LF);
52 protocols.append("Supported protocols");
53 protocols.append(StringUtils.LF);
54 for(Protocol p : ProtocolFactory.getEnabledProtocols()) {
55 protocols.append(p.getProvider()).append("\t").append(p.getDescription());
56 protocols.append(StringUtils.LF);
57 switch(p.getType()) {
58 case s3:
59 case googlestorage:
60 case swift:
61 case azure:
62 protocols.append("\t").append(String.format("%s://<container>/<key>", p.getProvider()));
63 break;
64 default:
65 protocols.append("\t").append(String.format("%s://<hostname>/<folder>/<file>", p.getProvider()));
66 break;
68 protocols.append(StringUtils.LF);
70 final StringBuilder header = new StringBuilder(StringUtils.LF);
71 header.append("\t");
72 header.append("URLs must be fully qualified. Paths can either denote "
73 + "a remote file (ftps://user@example.net/resource) or folder (ftps://user@example.net/directory/) "
74 + "with a trailing slash. You can reference files relative to your home directory with /~ (ftps://user@example.net/~/).");
75 header.append(protocols.toString());
76 final Preferences preferences = PreferencesFactory.get();
77 final Local profiles = LocalFactory.get(preferences.getProperty("application.support.path"),
78 PreferencesFactory.get().getProperty("profiles.folder.name"));
79 header.append(StringUtils.LF);
80 header.append(String.format("You can install additional connection profiles in %s",
81 profiles.getAbbreviatedPath()));
82 header.append(StringUtils.LF);
83 final StringBuilder footer = new StringBuilder(StringUtils.LF);
84 footer.append(String.format("Cyberduck is libre software licenced under the GPL. For general help about using Cyberduck, please refer to %s and the wiki at %s. For bug reports or feature requests open a ticket at %s.",
85 preferences.getProperty("website.cli"), preferences.getProperty("website.help"), MessageFormat.format(preferences.getProperty("website.bug"), preferences.getProperty("application.version"))));
86 final License l = LicenseFactory.find();
87 footer.append(StringUtils.LF);
88 if(l.verify()) {
89 footer.append(l.toString());
91 else {
92 footer.append("Not registered. Purchase a donation key to support the development of this software.");
94 formatter.printHelp("duck [options...]", header.toString(), options, footer.toString());