docs: public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
          this.stdin = new BufferedInputStream(stdin);
          this.stdout = stdout;
          this.stderr = stderr;
          this.locale = locale;
          registerOptionHandlers();
          CmdLineParser p = getCmdLineParser();
  
          // add options from the authenticator
          SecurityContext sc = null;
          Authentication old = null;
          Authentication auth = null;
          try {
              sc = SecurityContextHolder.getContext();
              old = sc.getAuthentication();
  
              sc.setAuthentication(auth = getTransportAuthentication());
  
              if (!(this instanceof HelpCommand || this instanceof WhoAmICommand))
                  Jenkins.getActiveInstance().checkPermission(Jenkins.READ);
              p.parseArgument(args.toArray(new String[0]));
              if (!(this instanceof HelpCommand || this instanceof WhoAmICommand))
                  Jenkins.getActiveInstance().checkPermission(Jenkins.READ);
              LOGGER.log(Level.FINE, "Invoking CLI command {0}, with {1} arguments, as user {2}.",
                      new Object[] {getName(), args.size(), auth.getName()});
              int res = run();
              LOGGER.log(Level.FINE, "Executed CLI command {0}, with {1} arguments, as user {2}, return code {3}",
                      new Object[] {getName(), args.size(), auth.getName(), res});
              return res;
          } catch (CmdLineException e) {
              LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.",
                      getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e);
              stderr.println("");
              stderr.println("ERROR: " + e.getMessage());
              printUsage(stderr, p);
              return 2;
          } catch (IllegalStateException e) {
              LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.",
                      getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e);
              stderr.println("");
              stderr.println("ERROR: " + e.getMessage());
              return 4;
          } catch (IllegalArgumentException e) {
              LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.",
                      getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e);
              stderr.println("");
              stderr.println("ERROR: " + e.getMessage());
              return 3;
          } catch (AbortException e) {
              LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.",
                      getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e);
              // signals an error without stack trace
              stderr.println("");
              stderr.println("ERROR: " + e.getMessage());
              return 5;
          } catch (AccessDeniedException e) {
              LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.",
                      getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e);
              stderr.println("");
              stderr.println("ERROR: " + e.getMessage());
              return 6;
          } catch (BadCredentialsException e) {
              // to the caller, we can't reveal whether the user didn't exist or the password didn't match.
              // do that to the server log instead
              String id = UUID.randomUUID().toString();
              LOGGER.log(Level.INFO, "CLI login attempt failed: " + id, e);
              stderr.println("");
              stderr.println("ERROR: Bad Credentials. Search the server log for " + id + " for more details.");
              return 7;
          } catch (Throwable e) {
              final String errorMsg = String.format("Unexpected exception occurred while performing %s command.",
                      getName());
              stderr.println("");
              stderr.println("ERROR: " + errorMsg);
              LOGGER.log(Level.WARNING, errorMsg, e);
              Functions.printStackTrace(e, stderr);
              return 1;
          } finally {
              if(sc != null)
                  sc.setAuthentication(old); // restore
          }
      }