Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Add API endpoint URL param to sy plugin list; add 'Provided By' to ou…
Browse files Browse the repository at this point in the history
…tput list
  • Loading branch information
binwiederhier committed Mar 12, 2015
1 parent df0ad03 commit c2bc4e5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
3 changes: 2 additions & 1 deletion gradle/bash/syncany.bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ _sy() {
PLUGIN_LIST_OPTIONS="\
-R --remote-only\
-L --local-only\
-s --snapshots"
-s --snapshots\
-a --api-endpoint"

PLUGIN_INSTALL_OPTIONS="\
-s --snapshot\
Expand Down
46 changes: 33 additions & 13 deletions syncany-cli/src/main/java/org/syncany/cli/PluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import joptsimple.OptionSpec;

public class PluginCommand extends Command {

private boolean minimalOutput = false;

@Override
Expand Down Expand Up @@ -73,6 +72,7 @@ public PluginOperationOptions parseOptions(String[] operationArgs) throws Except
OptionSpec<Void> optionRemote = parser.acceptsAll(asList("R", "remote-only"));
OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
OptionSpec<Void> optionMinimalOutput = parser.acceptsAll(asList("m", "minimal-output"));
OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();

OptionSet options = parser.parse(operationArgs);

Expand All @@ -94,6 +94,11 @@ public PluginOperationOptions parseOptions(String[] operationArgs) throws Except

// --snapshots
operationOptions.setSnapshots(options.has(optionSnapshots));

// --api-endpoint
if (options.has(optionApiEndpoint)) {
operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
}

// install|remove <plugin-id>
if (action == PluginOperationAction.INSTALL || action == PluginOperationAction.REMOVE) {
Expand Down Expand Up @@ -171,38 +176,53 @@ public void printResults(OperationResult operationResult) {
private void printResultList(PluginOperationResult operationResult) {
if (operationResult.getResultCode() == PluginResultCode.OK) {
List<String[]> tableValues = new ArrayList<String[]>();
tableValues.add(new String[]{"Id", "Name", "Local Version", "Type", "Remote Version", "Updatable"});
int outdated = 0;
int updatable = 0;

tableValues.add(new String[]{"Id", "Name", "Local Version", "Type", "Remote Version", "Updatable", "Provided By"});

int outdatedCount = 0;
int updatableCount = 0;
int thirdPartyCount = 0;

for (ExtendedPluginInfo extPluginInfo : operationResult.getPluginList()) {
PluginInfo pluginInfo = (extPluginInfo.isInstalled()) ? extPluginInfo.getLocalPluginInfo() : extPluginInfo.getRemotePluginInfo();

String localVersionStr = (extPluginInfo.isInstalled()) ? extPluginInfo.getLocalPluginInfo().getPluginVersion() : "";
String installedStr = extPluginInfo.isInstalled() ? (extPluginInfo.canUninstall() ? "User" : "Global") : "";
String remoteVersionStr = (extPluginInfo.isRemoteAvailable()) ? extPluginInfo.getRemotePluginInfo().getPluginVersion() : "";
String isOutdated = "";
String thirdPartyStr = (pluginInfo.isPluginThirdParty()) ? "Third Party" : "Syncany Team";
String updatableStr = "";

if (extPluginInfo.isInstalled() && extPluginInfo.isOutdated()) {
if (extPluginInfo.canUninstall()) {
isOutdated = "Auto";
updatable++;
updatableStr = "Auto";
updatableCount++;
}
else {
isOutdated = "Manual";
updatableStr = "Manual";
}

outdated++;
outdatedCount++;
}

tableValues.add(new String[]{pluginInfo.getPluginId(), pluginInfo.getPluginName(), localVersionStr, installedStr, remoteVersionStr, isOutdated});
if (pluginInfo.isPluginThirdParty()) {
thirdPartyCount++;
}

tableValues.add(new String[]{pluginInfo.getPluginId(), pluginInfo.getPluginName(), localVersionStr, installedStr, remoteVersionStr, updatableStr, thirdPartyStr});
}

CliTableUtil.printTable(out, tableValues, "No plugins found.");

if (outdated > 0) {
String isare = outdated == 1 ? "is" : "are";
out.printf("\nThere %s %d outdated %s, %d of them %s automatically updatable.\n", isare, outdated, outdated == 1 ? "plugin" : "plugins", updatable, isare);
if (outdatedCount > 0) {
String isAre = (outdatedCount == 1) ? "is" : "are";
String pluginPlugins = (outdatedCount == 1) ? "plugin" : "plugins";

out.printf("\nUpdates:\nThere %s %d outdated %s, %d of them %s automatically updatable.\n", isAre, outdatedCount, pluginPlugins, updatableCount, isAre);
}

if (thirdPartyCount > 0) {
String pluginPlugins = (thirdPartyCount == 1) ? "plugin" : "plugins";
out.printf("\nThird party plugins:\nPlease note that the Syncany Team does not take review or maintain the third-party %s\nlisted above. Please report issues to the corresponding plugin site.\n", pluginPlugins);
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NAME

SYNOPSIS
sy plugin list [-R | --remote-only] [-L | --local-only] [-s | --snapshots]
[<plugin-id>]
[-a | --api-endpoint=<url>] [<plugin-id>]

sy plugin install [-s | --snapshot] [-m | --minimal-output]
(<URL> | <file> | <plugin-id>)
Expand Down Expand Up @@ -63,6 +63,10 @@ ACIONS
-s, --snapshots
Instead of listing only plugin release versions (default), the result
list will also include daily snapshots (if newer snapshots exist).

-a, --api-endpoint=<url>
Selects the API endpoint to query for remote plugins. If not given,
the default endpoint URL will be used (https://api.syncany.org/v3).

install [<args>] (<URL> | <file> | <plugin-id>)
Installs a plugin from an arbitrary URL, local file or from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class PluginInfo {
@Element(name = "pluginConflictsWith", required = false)
private String conflictingPluginIds; // comma-separated

@Element(name = "pluginThirdParty", required = false)
private boolean pluginThirdParty;

@Element(name = "sha256sum", required = false)
private String sha256sum;

Expand Down Expand Up @@ -144,6 +147,14 @@ public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}

public boolean isPluginThirdParty() {
return pluginThirdParty;
}

public void setPluginThirdParty(boolean pluginThirdParty) {
this.pluginThirdParty = pluginThirdParty;
}

public List<String> getConflictingPluginIds() {
if (conflictingPluginIds != null) {
return Arrays.asList(conflictingPluginIds.split(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.syncany.util.EnvironmentUtil;
import org.syncany.util.FileUtil;
import org.syncany.util.StringUtil;

import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -90,7 +91,9 @@
public class PluginOperation extends Operation {
private static final Logger logger = Logger.getLogger(PluginOperation.class.getSimpleName());

private static final String PLUGIN_LIST_URL = "https://api.syncany.org/v2/plugins/list?appVersion=%s&snapshots=%s&pluginId=%s&os=%s&arch=%s";
private static final String API_DEFAULT_ENDPOINT_URL = "https://api.syncany.org/v3";
private static final String API_PLUGIN_LIST_REQUEST_FORMAT = "%s/plugins/list?appVersion=%s&snapshots=%s&pluginId=%s&os=%s&arch=%s";

private static final String PURGEFILE_FILENAME = "purgefile";
private static final String UPDATE_FILENAME = "updatefile";

Expand All @@ -110,7 +113,7 @@ public PluginOperation(Config config, PluginOperationOptions options) {

@Override
public PluginOperationResult execute() throws Exception {
result.setAction(options.getAction());
result.setAction(options.getAction());

switch (options.getAction()) {
case LIST:
Expand Down Expand Up @@ -611,9 +614,10 @@ private String getRemoteListStr(String pluginId) throws Exception {
String osStr = EnvironmentUtil.getOperatingSystemDescription();
String archStr = EnvironmentUtil.getArchDescription();

URL pluginListUrl = new URL(String.format(PLUGIN_LIST_URL, appVersion, snapshotsEnabled, pluginIdQueryStr, osStr, archStr));
String apiEndpointUrl = (options.getApiEndpoint() != null) ? options.getApiEndpoint() : API_DEFAULT_ENDPOINT_URL;
URL pluginListUrl = new URL(String.format(API_PLUGIN_LIST_REQUEST_FORMAT, apiEndpointUrl, appVersion, snapshotsEnabled, pluginIdQueryStr, osStr, archStr));

logger.log(Level.INFO, "Querying " + pluginListUrl + " ...");

eventBus.post(new PluginConnectToHostExternalEvent(pluginListUrl.getHost()));

URLConnection urlConnection = pluginListUrl.openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum PluginListMode {
private String pluginId = null;
private PluginListMode listMode = PluginListMode.ALL;
private boolean snapshots = false;
private String apiEndpoint = null;

public PluginOperationAction getAction() {
return action;
Expand Down Expand Up @@ -60,4 +61,12 @@ public boolean isSnapshots() {
public void setSnapshots(boolean snapshots) {
this.snapshots = snapshots;
}

public String getApiEndpoint() {
return apiEndpoint;
}

public void setApiEndpoint(String apiEndpoint) {
this.apiEndpoint = apiEndpoint;
}
}

0 comments on commit c2bc4e5

Please sign in to comment.