Class Command

  • Direct Known Subclasses:
    AbstractInitCommand, CleanupCommand, DaemonCommand, DebugCommand, DownCommand, LogCommand, LsCommand, LsRemoteCommand, PluginCommand, RestoreCommand, StatusCommand, UpCommand, UpdateCommand, WatchCommand

    public abstract class Command
    extends java.lang.Object
    Commands are the central part of Syncany's command line client. Each implementation of this abstract class represents a command that a user can run on the command line.

    The purpose of a command is to read required and optional arguments from the command line, run the corresponding operation, and display the results on the console. Implementations are not supposed to actually run any detailed logic, but are merely the user interface to collection options and print operation output.

    Implementations must implement the execute() method and the getRequiredCommandScope() method. While the former actually implements the logic, the latter specifies whether a command must be called inside (or outside) a local Syncany directory.

    Commands are automatically mapped from their camel case name on the command line to a class name using the CommandFactory. The command 'ls-remote', for instance, is mapped to the LsRemoteCommand.

    • Constructor Detail

    • Method Detail

      • execute

        public abstract int execute​(java.lang.String[] operationArgs)
                             throws java.lang.Exception
        This method implements the command-specific option-parsing, operation calling and output printing. To do so, the method must read and evaluate the given arguments, prepare a corresponding operation, call it and display the results according to a well-defined format.

        Implementations should not move any business logic in the execute method (or any other parts of the command).

        Parameters:
        operationArgs - Command-specific arguments (might also contain global options)
        Returns:
        Returns a return code
        Throws:
        java.lang.Exception - If the command or the corresponding operation fails
      • getRequiredCommandScope

        public abstract CommandScope getRequiredCommandScope()
        A command can either be executed within an initialized local directory or in a regular (non-Syncany) directory. Syncany determines this by searching for a .syncany folder.

        The required command scope resembles whether or not a command must be executed inside a .syncany directory or not -- or whether it does not matter.

        Returns:
        Returns the required command scope of the command
      • canExecuteInDaemonScope

        public abstract boolean canExecuteInDaemonScope()
        Returns whether a command can be run inside the scope of the daemon.

        If a folder is daemon-managed, the command line client passes the command to the daemon via REST and the daemon executes this command/operation. For some commands, this does not make sense or is dangerous. This method allows certain commands to be daemon-enabled, and other to be daemon-disabled.

      • parseOptions

        public abstract OperationOptions parseOptions​(java.lang.String[] operationArgs)
                                               throws java.lang.Exception
        A command can typically be configured using command line options. This method parses these command line options and returns an OperationOptions object representing the options.
        Throws:
        java.lang.Exception
      • printResults

        public abstract void printResults​(OperationResult result)
        A command typically prints a result to the console. This method takes an OperationResult object and formats it to be human-readable.
      • setLocalDir

        public void setLocalDir​(java.io.File localDir)
      • setOut

        public void setOut​(java.io.PrintStream out)