-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FS-928 Optimize bom cmd according to thread discussion. (#49)
* optimize bom cmd * fix typo and defer to Cobra
- Loading branch information
Showing
10 changed files
with
104 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package get | ||
|
||
import ( | ||
"log" | ||
|
||
mctl "github.com/metal-toolbox/mctl/cmd" | ||
"github.com/metal-toolbox/mctl/internal/app" | ||
"github.com/spf13/cobra" | ||
serverservice "go.hollow.sh/serverservice/pkg/api/v1" | ||
) | ||
|
||
type getBomInfoByBmcMacAddressFlags struct { | ||
aocMacAddr string | ||
bmcMacAddr string | ||
} | ||
|
||
func (gb *getBomInfoByBmcMacAddressFlags) hasAOCMacAddr() bool { | ||
return gb.aocMacAddr != "" | ||
} | ||
|
||
func (gb *getBomInfoByBmcMacAddressFlags) hasBMCMacAddr() bool { | ||
return gb.bmcMacAddr != "" | ||
} | ||
|
||
var ( | ||
flagsGetBomByMacAddress *getBomInfoByBmcMacAddressFlags | ||
) | ||
|
||
var getBomInfoByMacAddress = &cobra.Command{ | ||
Use: "bom", | ||
Short: "Get bom object by AOC or BMC Addr", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if !flagsGetBomByMacAddress.hasAOCMacAddr() && !flagsGetBomByMacAddress.hasBMCMacAddr() { | ||
log.Fatalf("--aoc-mac and --bmc-mac not set") | ||
} | ||
|
||
theApp := mctl.MustCreateApp(cmd.Context()) | ||
|
||
client, err := app.NewServerserviceClient(cmd.Context(), theApp.Config.Serverservice, theApp.Reauth) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var bomInfo *serverservice.Bom | ||
if flagsGetBomByMacAddress.hasAOCMacAddr() { | ||
bomInfo, _, err = client.GetBomInfoByAOCMacAddr(cmd.Context(), flagsGetBomByMacAddress.aocMacAddr) | ||
} else { | ||
bomInfo, _, err = client.GetBomInfoByBMCMacAddr(cmd.Context(), flagsGetBomByMacAddress.bmcMacAddr) | ||
} | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writeResults(bomInfo) | ||
}, | ||
} | ||
|
||
func init() { | ||
flagsGetBomByMacAddress = &getBomInfoByBmcMacAddressFlags{} | ||
|
||
getBomInfoByMacAddress.PersistentFlags().StringVar(&flagsGetBomByMacAddress.aocMacAddr, "aoc-mac", "", "get bom info by aoc mac address") | ||
getBomInfoByMacAddress.PersistentFlags().StringVar(&flagsGetBomByMacAddress.bmcMacAddr, "bmc-mac", "", "get bom info by bmc mac address") | ||
|
||
getBomInfoByMacAddress.MarkFlagsMutuallyExclusive("aoc-mac", "bmc-mac") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[Auto generated by spf13/cobra]: <> | ||
|
||
## mctl create bom | ||
|
||
Upload Bom File | ||
|
||
``` | ||
mctl create bom [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--from-xlsx-file string Xlsx file with bom informations | ||
-h, --help help for bom | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml) | ||
--reauth re-authenticate with oauth services | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [mctl create](mctl_create.md) - Create resources | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters