mirror of
https://github.com/MrAle98/sliver
synced 2026-06-08 11:54:46 +00:00
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package command
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/reeflective/console"
|
|
"github.com/rsteube/carapace"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
const defaultTimeout = 60
|
|
|
|
// Flags is a convenience function to bind flags to a given command.
|
|
// name - The name of the flag set (can be empty).
|
|
// cmd - The command to which the flags should be bound.
|
|
// flags - A function exposing the flag set through which flags are declared.
|
|
func Flags(name string, persistent bool, cmd *cobra.Command, flags func(f *pflag.FlagSet)) {
|
|
flagSet := pflag.NewFlagSet(name, pflag.ContinueOnError) // Create the flag set.
|
|
flags(flagSet) // Let the user bind any number of flags to it.
|
|
|
|
if persistent {
|
|
cmd.PersistentFlags().AddFlagSet(flagSet)
|
|
} else {
|
|
cmd.Flags().AddFlagSet(flagSet)
|
|
}
|
|
}
|
|
|
|
// FlagComps is a convenience function for adding completions to a command's flags.
|
|
// cmd - The command owning the flags to complete.
|
|
// bind - A function exposing a map["flag-name"]carapace.Action.
|
|
func FlagComps(cmd *cobra.Command, bind func(comp *carapace.ActionMap)) {
|
|
comps := make(carapace.ActionMap)
|
|
bind(&comps)
|
|
|
|
carapace.Gen(cmd).FlagCompletion(comps)
|
|
}
|
|
|
|
// hideCommand generates a cobra annotation map with a single
|
|
// console.CommandHiddenFilter key, which value is a comma-separated list
|
|
// of filters to use in order to expose/hide commands based on requirements.
|
|
// Ex: cmd.Annotations = hideCommand("windows") will hide the cmd
|
|
// if the target session/beacon is not a Windows host.
|
|
func hideCommand(filters ...string) map[string]string {
|
|
if len(filters) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if len(filters) == 1 {
|
|
return map[string]string{
|
|
console.CommandFilterKey: filters[0],
|
|
}
|
|
}
|
|
|
|
filts := strings.Join(filters, ",")
|
|
|
|
return map[string]string{
|
|
console.CommandFilterKey: filts,
|
|
}
|
|
}
|