From f639fef9922a4773cf26e92b7351458d3a1b792e Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sun, 16 Oct 2022 13:17:12 -0700 Subject: [PATCH] Add resource loading as part of DFU --- cmd/itctl/firmware.go | 13 +++++++++++++ cmd/itctl/main.go | 5 +++++ cmd/itctl/resources.go | 11 ++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/itctl/firmware.go b/cmd/itctl/firmware.go index cc11df8..bcf41fb 100644 --- a/cmd/itctl/firmware.go +++ b/cmd/itctl/firmware.go @@ -11,6 +11,19 @@ import ( ) func fwUpgrade(c *cli.Context) error { + resources := c.String("resources") + if resources != "" { + absRes, err := filepath.Abs(resources) + if err != nil { + return err + } + + err = resLoad(c.Context, []string{absRes}) + if err != nil { + return err + } + } + start := time.Now() var upgType api.UpgradeType diff --git a/cmd/itctl/main.go b/cmd/itctl/main.go index dbc8112..c4f865d 100644 --- a/cmd/itctl/main.go +++ b/cmd/itctl/main.go @@ -143,6 +143,11 @@ func main() { Aliases: []string{"f"}, Usage: "Path to firmware image (.bin file)", }, + &cli.PathFlag{ + Name: "resources", + Aliases: []string{"r"}, + Usage: "Path to resources file (.zip file)", + }, &cli.PathFlag{ Name: "archive", Aliases: []string{"a"}, diff --git a/cmd/itctl/resources.go b/cmd/itctl/resources.go index 6bbca0e..2e5338e 100644 --- a/cmd/itctl/resources.go +++ b/cmd/itctl/resources.go @@ -1,6 +1,7 @@ package main import ( + "context" "path/filepath" "github.com/cheggaaa/pb/v3" @@ -9,7 +10,11 @@ import ( ) func resourcesLoad(c *cli.Context) error { - if c.Args().Len() == 0 { + return resLoad(c.Context, c.Args().Slice()) +} + +func resLoad(ctx context.Context, args []string) error { + if len(args) == 0 { return cli.Exit("Command load requires one argument.", 1) } @@ -19,12 +24,12 @@ func resourcesLoad(c *cli.Context) error { // Start full bar at 0 total bar := pb.ProgressBarTemplate(rmTmpl).Start(0) - path, err := filepath.Abs(c.Args().Get(0)) + path, err := filepath.Abs(args[0]) if err != nil { return err } - progCh, err := client.LoadResources(c.Context, path) + progCh, err := client.LoadResources(ctx, path) if err != nil { return err }