Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Make order.yaml file optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bougou committed Oct 9, 2021
1 parent ba37633 commit 083635d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/en/sail-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ List all components for the specified product.
```bash
$ ./sail list-components -p <productName>
the product <productName> contains the following components:
the product <productName> contains (<number>) components:
- <componentName1>
- <componentName2>
- ...
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (o *BundleOptions) Run() error {
}

components := product.ComponentList()
fmt.Printf("the product %s contains the following components:\n", o.productName)
fmt.Printf("the product %s contains (%d) components:\n", o.productName, len(components))
for _, c := range components {
fmt.Printf("- %s\n", c)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/listcomponents/listcomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (o *ListComponentsOptions) Run() error {
}

components := product.ComponentList()
fmt.Printf("the product %s contains the following components:\n", o.productName)
fmt.Printf("the product %s contains (%d) components:\n", o.productName, len(components))
for _, c := range components {
fmt.Printf("- %s\n", c)
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/models/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,19 +455,22 @@ func (p *Product) checkPortsConflict(cm *cmdb.CMDB) error {
// loadOrder init the order field of product.
// It must loaded after loadComponents
func (p *Product) loadOrder() error {
order := make([]string, 0)

b, err := os.ReadFile(p.orderFile)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
msg := fmt.Sprintf("not found order file (%s) for product (%s)", p.orderFile, p.Name)
return errors.New(msg)
// use default order
order = append(order, p.ComponentList()...)
p.order = dedupSliceString(order)
return nil
}
return err

return fmt.Errorf("read file (%s) failed, err: %s", p.orderFile, err)
}

order := make([]string, 0)
if err := yaml.Unmarshal(b, &order); err != nil {
msg := fmt.Sprintf("unmarshal order for product (%s) failed, err: %s", p.Name, err)
return errors.New(msg)
return fmt.Errorf("unmarshal order for product (%s) failed, err: %s", p.Name, err)
}

for _, v := range order {
Expand All @@ -478,9 +481,7 @@ func (p *Product) loadOrder() error {

order = append(order, p.ComponentList()...)
p.order = dedupSliceString(order)

return nil

}

func dedupSliceString(stringSlice []string) []string {
Expand Down

0 comments on commit 083635d

Please sign in to comment.