Skip to content

Commit

Permalink
swctl: Create path for entity extra files (#134)
Browse files Browse the repository at this point in the history
Create path for entity extra files

Also do not ignore error during entity file loading.

Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak authored Oct 6, 2023
1 parent dd652a7 commit e0811c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmd/swctl/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ func (cli *CLI) Initialize(opts *GlobalOptions) (err error) {

// load entity files
cli.entities, err = loadEntityFiles(opts.EntityFiles)
if err != nil {
return fmt.Errorf("loading entity files failed: %w", err)
}
if cli.entities == nil {
cli.entities, err = loadEmbeddedEntities(opts.EmbeddedEntityByte)

}
if err != nil {
return fmt.Errorf("loading entity files failed: %v", err)
return fmt.Errorf("loading embedded entity files failed: %w", err)
}

// get vpp-probe
Expand Down
6 changes: 5 additions & 1 deletion cmd/swctl/app/cmd_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/netip"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -298,8 +299,11 @@ func runManageCmd(cli Cli, opts ManageOptions, args []string) error {

logrus.Tracef(" - final vars:\n%s\nraw file %s:\n%v", yamlTmpl(vars), f.Name, rawData)

if err := os.MkdirAll(filepath.Dir(f.Name), 0777); err != nil {
return fmt.Errorf("failed to create directory for file (%s): %w", f.Name, err)
}
if err := os.WriteFile(f.Name, []byte(rawData), 0666); err != nil {
return fmt.Errorf("failed to write file (%v): %w", f.Name, err)
return fmt.Errorf("failed to write file (%s): %w", f.Name, err)
}
}
}
Expand Down

0 comments on commit e0811c7

Please sign in to comment.