Class BaseCommand

    • Constructor Detail

      • BaseCommand

        public BaseCommand()
    • Method Detail

      • setInputStream

        public void setInputStream​(InputStream in)
        Specified by:
        setInputStream in interface org.apache.sshd.server.command.Command
      • setOutputStream

        public void setOutputStream​(OutputStream out)
        Specified by:
        setOutputStream in interface org.apache.sshd.server.command.Command
      • setErrorStream

        public void setErrorStream​(OutputStream err)
        Specified by:
        setErrorStream in interface org.apache.sshd.server.command.Command
      • setExitCallback

        public void setExitCallback​(org.apache.sshd.server.ExitCallback callback)
        Specified by:
        setExitCallback in interface org.apache.sshd.server.command.Command
      • getPluginName

        protected String getPluginName()
      • getName

        protected String getName()
      • getArguments

        public String[] getArguments()
      • setArguments

        public void setArguments​(String[] argv)
      • getTrimmedArguments

        protected String[] getTrimmedArguments()
        Trim the argument if it is spanning multiple lines.
        Returns:
        the arguments where all the multiple-line fields are trimmed.
      • destroy

        public void destroy​(org.apache.sshd.server.channel.ChannelSession channel)
        Specified by:
        destroy in interface org.apache.sshd.server.command.CommandLifecycle
      • provideStateTo

        protected void provideStateTo​(org.apache.sshd.server.command.Command cmd)
        Pass all state into the command, then run its start method.

        This method copies all critical state, like the input and output streams, into the supplied command. The caller must still invoke cmd.start() if wants to pass control to the command.

        Parameters:
        cmd - the command that will receive the current state.
      • parseCommandLine

        protected void parseCommandLine()
                                 throws BaseCommand.UnloggedFailure
        Parses the command line argument, injecting parsed values into fields.

        This method must be explicitly invoked to cause a parse.

        Throws:
        BaseCommand.UnloggedFailure - if the command line arguments were invalid.
        See Also:
        Option, Argument
      • parseCommandLine

        protected void parseCommandLine​(Object options)
                                 throws BaseCommand.UnloggedFailure
        Parses the command line argument, injecting parsed values into fields.

        This method must be explicitly invoked to cause a parse.

        Parameters:
        options - object whose fields declare Option and Argument annotations to describe the parameters of the command. Usually this.
        Throws:
        BaseCommand.UnloggedFailure - if the command line arguments were invalid.
        See Also:
        Option, Argument
      • usage

        protected String usage()
      • newCmdLineParser

        protected com.google.gerrit.util.cli.CmdLineParser newCmdLineParser​(Object options)
        Construct a new parser for this command's received command line.
      • startThread

        protected void startThread​(BaseCommand.CommandRunnable thunk,
                                   AccessPath accessPath)
        Spawn a function into its own thread.

        Typically this should be invoked within CommandLifecycle.start(ChannelSession, Environment), such as:

         startThread(new CommandRunnable() {
           public void run() throws Exception {
             runImp();
           }
         },
         accessPath);
         

        If the function throws an exception, it is translated to a simple message for the client, a non-zero exit code, and the stack trace is logged.

        Parameters:
        thunk - the runnable to execute on the thread, performing the command's logic.
        accessPath - the path used by the end user for running the SSH command
      • onExit

        protected void onExit​(int rc)
        Terminate this command and return a result code to the remote client.

        Commands should invoke this at most once. Once invoked, the command may lose access to request based resources as any callbacks previously registered with RequestCleanup will fire.

        Parameters:
        rc - exit code for the remote client.
      • toPrintWriter

        protected static PrintWriter toPrintWriter​(OutputStream o)
        Wrap the supplied output stream in a UTF-8 encoded PrintWriter.
      • writeError

        protected void writeError​(String type,
                                  String msg)
      • enableGracefulStop

        protected void enableGracefulStop()
      • getTaskDescription

        protected String getTaskDescription()