backy/pkg/backy/list.go
Andrew Woodlee 7be2679b91
All checks were successful
ci/woodpecker/push/go-lint Pipeline was successful
change: Commands: host can now be localhost or 127.0.0.1 to run commands locally
2025-03-21 09:09:56 -05:00

114 lines
2.0 KiB
Go

package backy
import "fmt"
/*
Command: command [args...]
Host: Local or remote (list the name)
List: name
Commands:
flags: list commands
if listcommands: (use list command)
Command: command [args...]
Host: Local or remote (list the name)
*/
// ListCommand searches the commands in the file to find one
func (opts *ConfigOpts) ListCommand(cmd string) {
// bool for commands not found
// gets set to false if a command is not found
// set to true if the command is found
var cmdFound bool = false
var cmdInfo *Command
// check commands in file against cmd
for cmdInFile := range opts.Cmds {
cmdFound = false
if cmd == cmdInFile {
cmdFound = true
cmdInfo = opts.Cmds[cmd]
break
}
}
// print the command's information
if cmdFound {
println("Command: ")
print(cmdInfo.Cmd)
for _, v := range cmdInfo.Args {
print(" ") // print space between command and args
print(v) // print command arg
}
// is it remote or local
if !IsHostLocal(cmdInfo.Host) {
println()
print("Host: ", cmdInfo.Host)
println()
} else {
println()
print("Host: Runs on Local Machine\n\n")
}
if cmdInfo.Dir != nil {
println()
print("Directory: ", *cmdInfo.Dir)
println()
}
if cmdInfo.Type.String() != "" {
print("Type: ", cmdInfo.Type.String())
println()
}
} else {
fmt.Printf("Command %s not found. Check spelling.\n", cmd)
}
}
func (opts *ConfigOpts) ListCommandList(list string) {
// bool for commands not found
// gets set to false if a command is not found
// set to true if the command is found
var listFound bool = false
var listInfo *CmdList
// check commands in file against cmd
for listInFile, l := range opts.CmdConfigLists {
listFound = false
if list == listInFile {
listFound = true
listInfo = l
break
}
}
// print the command's information
if listFound {
println("List: ", list)
println()
for _, v := range listInfo.Order {
println()
opts.ListCommand(v)
}
} else {
fmt.Printf("List %s not found. Check spelling.\n", list)
}
}