Files
threshold/internal/cmd/commands/hostscmd/static_funcs.go
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

90 lines
2.2 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package hostscmd
import (
"repo.anhonesthost.net/CyberCoveLLC/threshold/api/hosts"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/cmd/base"
)
func init() {
extraStaticActionsFlagsMapFunc = extraStaticActionsFlagsMapFuncImpl
extraStaticFlagsFunc = extraStaticFlagsFuncImpl
extraStaticFlagsHandlingFunc = extraStaticFlagsHandlingFuncImpl
}
type extraStaticCmdVars struct {
flagAddress string
}
func extraStaticActionsFlagsMapFuncImpl() map[string][]string {
return map[string][]string{
"create": {"address"},
"update": {"address"},
}
}
func (c *StaticCommand) extraStaticHelpFunc(helpMap map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: threshold hosts create static [options] [args]",
"",
" Create a static-type host. Example:",
"",
` $ threshold hosts create static -name prodops -description "Static host for ProdOps" -address "127.0.0.1"`,
"",
"",
})
case "update":
helpStr = base.WrapForHelpText([]string{
"Usage: threshold hosts update static [options] [args]",
"",
" Update a static-type host given its ID. Example:",
"",
` $ threshold hosts update static -id hst_1234567890 -name "devops" -description "Static host for DevOps" -address "10.20.30.40"`,
"",
"",
})
default:
helpStr = helpMap[c.Func]()
}
return helpStr + c.Flags().Help()
}
func extraStaticFlagsFuncImpl(c *StaticCommand, set *base.FlagSets, _ *base.FlagSet) {
f := set.NewFlagSet("Static Host Options")
for _, name := range flagsStaticMap[c.Func] {
switch name {
case "address":
f.StringVar(&base.StringVar{
Name: "address",
Target: &c.flagAddress,
Usage: "The address of the host",
})
}
}
}
func extraStaticFlagsHandlingFuncImpl(c *StaticCommand, _ *base.FlagSets, opts *[]hosts.Option) bool {
if c.Func == "create" && c.flagAddress == "" {
c.UI.Error("Address must be provided via -address")
return false
}
switch c.flagAddress {
case "":
case "null":
*opts = append(*opts, hosts.DefaultStaticHostAddress())
default:
*opts = append(*opts, hosts.WithStaticHostAddress(c.flagAddress))
}
return true
}