Skip to content

Commit

Permalink
args: Allow setting version on command line
Browse files Browse the repository at this point in the history
We were only support version from the YAML file, now support
setting directly on the command line for swupd.

Signed-off-by: Mark D Horn <[email protected]>
  • Loading branch information
mdhorn committed Oct 8, 2019
1 parent 2187466 commit a3ac0ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Args struct {
SwupdCertPath string
SwupdStateClean bool
SwupdFormat string
SwupdVersion string
SwupdContentURL string
SwupdVersionURL string
SwupdURL string
Expand Down Expand Up @@ -194,6 +195,10 @@ func (args *Args) setCommandLineArgs() (err error) {
&args.SwupdFormat, "swupd-format", args.SwupdFormat, "Swupd --format argument",
)

flag.StringVar(
&args.SwupdVersion, "swupd-version", args.SwupdVersion, "Swupd --version argument",
)

flag.StringVar(
&args.SwupdContentURL, "swupd-contenturl", args.SwupdContentURL,
"Swupd --contenturl argument",
Expand Down
3 changes: 3 additions & 0 deletions args/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ func TestKernelAndCommandlineAllArgs(t *testing.T) {
if testArgs.SwupdMirror != "" {
t.Errorf("Command Line 'mirror' is not defaulted to ''")
}
if testArgs.SwupdVersion != "" {
t.Errorf("Command Line 'swupd-version' is not defaulted to ''")
}
if testArgs.PamSalt != "" {
t.Errorf("Command Line 'genpwd' is not defaulted to ''")
}
Expand Down
13 changes: 13 additions & 0 deletions clr-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
"syscall"

Expand Down Expand Up @@ -289,6 +290,18 @@ func execute(options args.Args) error {
if options.SwupdFormat != "" {
md.SwupdFormat = options.SwupdFormat
}
if options.SwupdVersion != "" {
if strings.EqualFold(options.SwupdVersion, "latest") {
md.Version = 0
} else {
version, err := strconv.ParseUint(options.SwupdVersion, 10, 32)
if err == nil {
md.Version = uint(version)
} else {
log.Warning("Failed to parse swupd-version : %s; not-used!", options.SwupdVersion)
}
}
}

if options.AllowInsecureHTTPSet {
md.AllowInsecureHTTP = options.AllowInsecureHTTP
Expand Down

0 comments on commit a3ac0ad

Please sign in to comment.