Skip to content

Commit

Permalink
FS-928 Optimize bom cmd according to thread discussion. (#49)
Browse files Browse the repository at this point in the history
* optimize bom cmd

* fix typo and defer to Cobra
  • Loading branch information
Alva8756 authored Sep 26, 2023
1 parent f029305 commit e2253c2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 106 deletions.
2 changes: 1 addition & 1 deletion cmd/create/bomupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
)

var uploadBomFile = &cobra.Command{
Use: "uploadbom",
Use: "bom",
Short: "Upload Bom File",
Run: func(cmd *cobra.Command, args []string) {
theApp := mctl.MustCreateApp(cmd.Context())
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var create = &cobra.Command{
Use: "create",
Short: "Create resources",
Run: func(cmd *cobra.Command, args []string) {
commands := []string{"firmware", "firmware-set", "uploadbom"}
commands := []string{"firmware", "firmware-set", "bom"}
log.Fatal("A valid create command parameter was expected: " + strings.Join(commands, ", "))
},
}
Expand Down
47 changes: 0 additions & 47 deletions cmd/get/aoc-mac-address.go

This file was deleted.

47 changes: 0 additions & 47 deletions cmd/get/bmc-mac-address.go

This file was deleted.

65 changes: 65 additions & 0 deletions cmd/get/bom.go
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")
}
3 changes: 1 addition & 2 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func init() {
cmdGet.AddCommand(getFirmware)
cmdGet.AddCommand(getFirmwareSet)
cmdGet.AddCommand(getBiosConfig)
cmdGet.AddCommand(getBomInfoByAocMacAddress)
cmdGet.AddCommand(getBomInfoByBmcMacAddress)
cmdGet.AddCommand(getBomInfoByMacAddress)

cmdGet.PersistentFlags().StringVarP(&output, "output", "o", "json", "{json|text}")
}
2 changes: 1 addition & 1 deletion docs/mctl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mctl create [flags]
### SEE ALSO

* [mctl](mctl.md) - mctl is a CLI utility to interact with metal toolbox services
* [mctl create bom](mctl_create_bom.md) - Upload Bom File
* [mctl create firmware](mctl_create_firmware.md) - Create firmware
* [mctl create firmware-set](mctl_create_firmware-set.md) - Create a firmware set
* [mctl create uploadbom](mctl_create_uploadbom.md) - Upload Bom File

28 changes: 28 additions & 0 deletions docs/mctl_create_bom.md
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

3 changes: 1 addition & 2 deletions docs/mctl_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ mctl get [flags]
### SEE ALSO

* [mctl](mctl.md) - mctl is a CLI utility to interact with metal toolbox services
* [mctl get aocmacaddress](mctl_get_aocmacaddress.md) - Get bom object by aocMacAddr
* [mctl get bios-config](mctl_get_bios-config.md) - Get bios configuration information for a server
* [mctl get bmcmacaddress](mctl_get_bmcmacaddress.md) - Get bom object by bmcMacAddr
* [mctl get bom](mctl_get_bom.md) - Get bom object by AOC or BMC Addr
* [mctl get component](mctl_get_component.md) - get server components
* [mctl get condition](mctl_get_condition.md) - get server condition
* [mctl get firmware](mctl_get_firmware.md) - Get information for given firmware identifier
Expand Down
11 changes: 6 additions & 5 deletions docs/mctl_get_aocMacAddress.md → docs/mctl_get_bom.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[Auto generated by spf13/cobra]: <>

## mctl get aocmacaddress
## mctl get bom

Get bom object by aocMacAddr
Get bom object by AOC or BMC Addr

```
mctl get aocmacaddress [flags]
mctl get bom [flags]
```

### Options

```
--get-bom-by-aoc-mac-address string get bom info by aocMacAddr
-h, --help help for aocmacaddress
--aoc-mac string get bom info by aoc mac address
--bmc-mac string get bom info by bmc mac address
-h, --help help for bom
```

### Options inherited from parent commands
Expand Down

0 comments on commit e2253c2

Please sign in to comment.