Skip to content

Commit

Permalink
prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
tbauriedel committed Jun 28, 2024
1 parent 45dd6b7 commit 5f2adae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
42 changes: 42 additions & 0 deletions internal/arguments/arguments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package arguments

import (
"bufio"
"fmt"
"os"
"strings"
)

func NewStringVar(callback *string, value string, usage string) {
scanner := bufio.NewScanner(os.Stdin)

for {
fmt.Printf("%s - (Default: %s): ", usage, value)
if scanner.Scan() {
input := scanner.Text()
if input != "" {
*callback = input
break
} else {
*callback = value
break
}
} else {
if err := scanner.Err(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, "reading standard input:", err)
break
}
}
}
}

func NewStringSliceVar(callback *[]string, value []string, usage string) {
var input string
NewStringVar(&input, strings.Join(value, ","), usage)

*callback = strings.Split(input, ",")
}

func NewBoolVar() {

}
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/NETWAYS/support-collector/internal/arguments"
"github.com/NETWAYS/support-collector/internal/metrics"
"os"
"path/filepath"
Expand Down Expand Up @@ -184,10 +185,14 @@ func main() {
}

func handleArguments() {
// TODO only a prototype
arguments.NewStringVar(&outputFile, buildFileName(), "Output file for the ZIP content")
arguments.NewStringSliceVar(&enabledModules, moduleOrder, "Comma seperated list of enabled module")

// arguments for collection handling
flag.StringSliceVar(&enabledModules, "enable", moduleOrder, "List of enabled module")
//flag.StringSliceVar(&enabledModules, "enable", moduleOrder, "List of enabled module")
flag.StringSliceVar(&disabledModules, "disable", []string{}, "List of disabled module")
flag.StringVarP(&outputFile, "output", "o", buildFileName(), "Output file for the ZIP content")
//flag.StringVarP(&outputFile, "output", "o", buildFileName(), "Output file for the ZIP content")
flag.BoolVar(&noDetailedCollection, "nodetails", false, "Disable detailed collection including logs and more")
flag.StringArrayVar(&extraObfuscators, "hide", []string{}, "List of additional strings to obfuscate. Can be used multiple times and supports regex.") //nolint:lll
flag.DurationVar(&commandTimeout, "command-timeout", commandTimeout, "Timeout for command execution in modules")
Expand Down

0 comments on commit 5f2adae

Please sign in to comment.