feat/version (#2)

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-03-25 19:25:12 +11:00
parent 13b0f12edf
commit f65864af22
7 changed files with 119 additions and 23 deletions
+14 -4
View File
@@ -25,6 +25,8 @@ const (
appName = "node-lookup"
)
var version = "dev"
// config holds all configurable values. Fields map 1:1 to config file keys,
// env vars (NODE_LOOKUP_*), and (where applicable) CLI flags.
type config struct {
@@ -148,7 +150,7 @@ func queryPuppetDB(puppetDBURL, query string) ([]fact, error) {
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
@@ -174,7 +176,7 @@ func valueString(raw json.RawMessage) string {
func valueAny(raw json.RawMessage) interface{} {
var v interface{}
json.Unmarshal(raw, &v)
_ = json.Unmarshal(raw, &v)
return v
}
@@ -298,7 +300,7 @@ func run(cfg config, nodeName, factName, match, partialMatch string, showRole, n
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.SetEscapeHTML(false)
enc.Encode(hostFactMap)
_ = enc.Encode(hostFactMap)
case count:
values := stdinLines
@@ -317,7 +319,7 @@ func run(cfg config, nodeName, factName, match, partialMatch string, showRole, n
"all": map[string]interface{}{"hosts": hosts},
}
b, _ := yaml.Marshal(inventory)
os.Stdout.Write(b)
_, _ = os.Stdout.Write(b)
case nodeOnly:
for _, line := range returnData {
@@ -419,6 +421,14 @@ func main() {
configCmd.AddCommand(configInitCmd, configShowCmd)
rootCmd.AddCommand(configCmd)
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version",
Run: func(cmd *cobra.Command, args []string) { fmt.Println(version) },
SilenceUsage: true,
}
rootCmd.AddCommand(versionCmd)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}