Add uri positional argument and remove uri flag

This commit is contained in:
Alex Lovell-Troy 2024-07-01 10:59:42 -04:00
parent 5f86f9a378
commit 3386690f17
No known key found for this signature in database

View file

@ -3,17 +3,29 @@ package cmd
import (
"encoding/json"
"fmt"
"net/url"
"github.com/OpenCHAMI/magellan/pkg/crawler"
"github.com/spf13/cobra"
)
var crawlCmd = &cobra.Command{
Use: "crawl",
Use: "crawl [uri]",
Short: "Crawl a single BMC for inventory information",
Args: func(cmd *cobra.Command, args []string) error {
// Validate that the only argument is a valid URI
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
_, err := url.ParseRequestURI(args[0])
if err != nil {
return fmt.Errorf("invalid URI specified: %s", args[0])
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
systems, err := crawler.CrawlBMC(crawler.CrawlerConfig{
URI: cmd.Flag("uri").Value.String(),
URI: args[0],
Username: cmd.Flag("username").Value.String(),
Password: cmd.Flag("password").Value.String(),
Insecure: cmd.Flag("insecure").Value.String() == "true",
@ -34,8 +46,7 @@ var crawlCmd = &cobra.Command{
}
func init() {
crawlCmd.Flags().StringP("uri", "u", "", "URI of the BMC")
crawlCmd.Flags().StringP("username", "n", "", "Username for the BMC")
crawlCmd.Flags().StringP("username", "u", "", "Username for the BMC")
crawlCmd.Flags().StringP("password", "p", "", "Password for the BMC")
crawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors")