add help.go, splog.go module

This commit is contained in:
2026-04-29 14:08:59 +08:00
parent 53d56ec6e2
commit e762cbdfe3
8 changed files with 415 additions and 10 deletions

View File

@@ -0,0 +1,40 @@
package control
import (
"os"
"github.com/spf13/cobra"
"gitea.sunhpc.com/kelvin/sunhpc/internal/app/control/version"
"gitea.sunhpc.com/kelvin/sunhpc/internal/pkg/help"
"gitea.sunhpc.com/kelvin/sunhpc/internal/pkg/splog"
)
var (
rootCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "sunhpc control COMMAND [options] [FLAGS]",
Short: "Sunhpc Control",
Long: `Control interface to the SunHPC Cluster Provisioning System.`,
PersistentPreRunE: rootPersistentPreRunE,
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
}
verboseArg bool
DebugFlag bool
SunhpcConfArg string
AllowEmptyConf bool
)
func init() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "debug output")
rootCmd.PersistentFlags().IntVar(&LogLevel, "loglevel", splog.INFO, "Set log level to given string")
_ = rootCmd.PersistentFlags().MarkHidden("loglevel")
rootCmd.PersistentFlags().StringVar(&SunhpcConfArg, "sunhpcconf", "", "Set the sunhpc configuration file")
rootCmd.PersistentFlags().BoolVar(&AllowEmptyConf, "emptyconf", false, "Allow empty configuration")
_ = rootCmd.PersistentFlags().MarkHidden("emptyconf")
rootCmd.SetUsageTemplate(help.UsageTemplate)
rootCmd.SetHelpTemplate(help.HelpTemplate)
}