Add resource loading as part of DFU

This commit is contained in:
Elara 2022-10-16 13:17:12 -07:00
parent 2d0db1dcf1
commit f639fef992
3 changed files with 26 additions and 3 deletions

View File

@ -11,6 +11,19 @@ import (
) )
func fwUpgrade(c *cli.Context) error { 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() start := time.Now()
var upgType api.UpgradeType var upgType api.UpgradeType

View File

@ -143,6 +143,11 @@ func main() {
Aliases: []string{"f"}, Aliases: []string{"f"},
Usage: "Path to firmware image (.bin file)", Usage: "Path to firmware image (.bin file)",
}, },
&cli.PathFlag{
Name: "resources",
Aliases: []string{"r"},
Usage: "Path to resources file (.zip file)",
},
&cli.PathFlag{ &cli.PathFlag{
Name: "archive", Name: "archive",
Aliases: []string{"a"}, Aliases: []string{"a"},

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"path/filepath" "path/filepath"
"github.com/cheggaaa/pb/v3" "github.com/cheggaaa/pb/v3"
@ -9,7 +10,11 @@ import (
) )
func resourcesLoad(c *cli.Context) error { 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) 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 // Start full bar at 0 total
bar := pb.ProgressBarTemplate(rmTmpl).Start(0) bar := pb.ProgressBarTemplate(rmTmpl).Start(0)
path, err := filepath.Abs(c.Args().Get(0)) path, err := filepath.Abs(args[0])
if err != nil { if err != nil {
return err return err
} }
progCh, err := client.LoadResources(c.Context, path) progCh, err := client.LoadResources(ctx, path)
if err != nil { if err != nil {
return err return err
} }