Skip to content

Commit fb912b5

Browse files
committed
Fix command line parser
1 parent 1b15377 commit fb912b5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

client/ui/update/main.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package update
33
import (
44
"context"
55
"flag"
6+
"fmt"
67
"os"
78
"path/filepath"
89
"strings"
@@ -28,6 +29,28 @@ func init() {
2829
flag.BoolVar(&dryRunFlag, "dry-run", false, "dry run the update process without making any changes")
2930
}
3031

32+
func parseFlags() {
33+
flag.Parse()
34+
35+
missing := []string{}
36+
37+
if tempDirFlag == "" {
38+
missing = append(missing, "-temp-dir")
39+
}
40+
if targetVersionFlag == "" {
41+
missing = append(missing, "-target-version")
42+
}
43+
if serviceDirFlag == "" {
44+
missing = append(missing, "-service-dir")
45+
}
46+
47+
if len(missing) > 0 {
48+
fmt.Printf("Error: missing required flags: %s\n\n", strings.Join(missing, ", "))
49+
flag.Usage()
50+
os.Exit(2)
51+
}
52+
}
53+
3154
// IsUpdateBinary checks if the current executable is named "update" or "update.exe"
3255
func IsUpdateBinary() bool {
3356
// Remove extension for cross-platform compatibility
@@ -42,13 +65,13 @@ func IsUpdateBinary() bool {
4265
}
4366

4467
func Execute() {
68+
parseFlags()
69+
4570
if err := setupLogToFile(tempDirFlag); err != nil {
4671
log.Errorf("failed to setup logging: %s", err)
4772
return
4873
}
4974

50-
// todo validate target version
51-
5275
ui := NewUI()
5376

5477
// Create a context with timeout for the entire update process

0 commit comments

Comments
 (0)