17609: Add diagnostics command.
[arvados.git] / lib / cmd / cmd.go
index 51bcf55c76040e1f8c3a1320fcf7ab50db2090c6..63d7576b4cc1964b11b29a8ac199730660325f2e 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: Apache-2.0
 
-// package cmd helps define reusable functions that can be exposed as
+// Package cmd helps define reusable functions that can be exposed as
 // [subcommands of] command line programs.
 package cmd
 
@@ -16,6 +16,8 @@ import (
        "runtime"
        "sort"
        "strings"
+
+       "github.com/sirupsen/logrus"
 )
 
 type Handler interface {
@@ -65,6 +67,11 @@ type Multi map[string]Handler
 
 func (m Multi) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
        _, basename := filepath.Split(prog)
+       if i := strings.Index(basename, "~"); i >= 0 {
+               // drop "~anything" suffix (arvados-dispatch-cloud's
+               // DeployRunnerBinary feature relies on this)
+               basename = basename[:i]
+       }
        cmd, ok := m[basename]
        if !ok {
                // "controller" command exists, and binary is named "arvados-controller"
@@ -148,3 +155,9 @@ func SubcommandToFront(args []string, flagset FlagSet) []string {
        copy(newargs[flagargs+1:], args[flagargs+1:])
        return newargs
 }
+
+type NoPrefixFormatter struct{}
+
+func (NoPrefixFormatter) Format(entry *logrus.Entry) ([]byte, error) {
+       return []byte(entry.Message + "\n"), nil
+}