|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 |
| - "os" |
6 |
| - "github.com/rs/zerolog/log" |
7 |
| - "sohot/e" |
8 |
| - "sohot/version" |
9 |
| - "sohot/watch" |
10 |
| - "sort" |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "sohot/e" |
| 7 | + "sohot/version" |
| 8 | + "sohot/watch" |
| 9 | + "sort" |
| 10 | + "strings" |
11 | 11 |
|
12 |
| - "github.com/manifoldco/promptui" |
| 12 | + "github.com/rs/zerolog/log" |
| 13 | + |
| 14 | + "github.com/manifoldco/promptui" |
13 | 15 | )
|
14 | 16 |
|
15 | 17 | //go:generate go install .
|
16 | 18 | func main() {
|
17 |
| - var key string |
18 |
| - |
19 |
| - // Check if command line arguments are provided |
20 |
| - if len(os.Args) > 1 { |
21 |
| - arg := os.Args[1] |
22 |
| - |
23 |
| - // Handle version commands |
24 |
| - if arg == "--version" || arg == "-v" || arg == "version" { |
25 |
| - buildInfo := version.GetBuildInfo() |
26 |
| - fmt.Println(buildInfo.String()) |
27 |
| - return |
28 |
| - } |
29 |
| - |
30 |
| - key = arg |
31 |
| - log.Info().Str("profile", key).Msg("Using command line specified profile") |
32 |
| - } else { |
33 |
| - // No arguments provided, show interactive selection interface |
34 |
| - items := make([]string, 0, len(e.V.Run)) |
35 |
| - for s, run := range e.V.Run { |
36 |
| - if run.Only { |
37 |
| - s += "#Run only mode" |
38 |
| - } |
39 |
| - items = append(items, s) |
40 |
| - } |
41 |
| - sort.Strings(items) |
42 |
| - prompt := promptui.Select{ |
43 |
| - Label: "Select profile", |
44 |
| - Items: items, |
45 |
| - } |
46 |
| - _, result, err := prompt.Run() |
| 19 | + var key string |
| 20 | + |
| 21 | + // Check if command line arguments are provided |
| 22 | + if len(os.Args) > 1 { |
| 23 | + arg := os.Args[1] |
| 24 | + |
| 25 | + // Handle version commands |
| 26 | + if arg == "--version" || arg == "-v" || arg == "version" { |
| 27 | + buildInfo := version.GetBuildInfo() |
| 28 | + fmt.Println(buildInfo.String()) |
| 29 | + return |
| 30 | + } |
| 31 | + |
| 32 | + key = arg |
| 33 | + log.Info().Str("profile", key).Msg("Using command line specified profile") |
| 34 | + } else { |
| 35 | + // No arguments provided, show interactive selection interface |
| 36 | + items := make([]string, 0, len(e.V.Run)) |
| 37 | + for s, run := range e.V.Run { |
| 38 | + if run.Only { |
| 39 | + s += "#Run only mode" |
| 40 | + } |
| 41 | + items = append(items, s) |
| 42 | + } |
| 43 | + sort.Strings(items) |
| 44 | + prompt := promptui.Select{ |
| 45 | + Label: "Select profile", |
| 46 | + Items: items, |
| 47 | + } |
| 48 | + _, result, err := prompt.Run() |
47 | 49 |
|
48 |
| - if err != nil { |
49 |
| - fmt.Printf("Prompt failed %v\n", err) |
50 |
| - return |
51 |
| - } |
52 |
| - key = extractKey(result) |
53 |
| - } |
54 |
| - |
55 |
| - // Verify if the profile exists |
56 |
| - run, ok := e.V.Run[key] |
57 |
| - if !ok { |
58 |
| - log.Fatal().Str("profile", key).Msg("Profile not found") |
59 |
| - } |
60 |
| - |
61 |
| - // Show version information at startup |
62 |
| - buildInfo := version.GetBuildInfo() |
63 |
| - log.Info().Str("version", buildInfo.Version).Str("commit", buildInfo.Commit).Msg("Starting SoHot") |
64 |
| - |
65 |
| - watch.Watching(run) |
66 |
| - watch.Building(run) |
| 50 | + if err != nil { |
| 51 | + fmt.Printf("Prompt failed %v\n", err) |
| 52 | + return |
| 53 | + } |
| 54 | + key = extractKey(result) |
| 55 | + } |
| 56 | + |
| 57 | + // Verify if the profile exists |
| 58 | + run, ok := e.V.Run[key] |
| 59 | + if !ok { |
| 60 | + log.Fatal().Str("profile", key).Msg("Profile not found") |
| 61 | + } |
| 62 | + |
| 63 | + // Show version information at startup |
| 64 | + buildInfo := version.GetBuildInfo() |
| 65 | + log.Info().Str("version", buildInfo.Version).Str("commit", buildInfo.Commit).Msg("Starting SoHot") |
| 66 | + |
| 67 | + watch.Watching(run) |
| 68 | + watch.Building(run) |
| 69 | +} |
| 70 | +func extractKey(result string) string { |
| 71 | + if idx := strings.Index(result, "#"); idx != -1 { |
| 72 | + return result[:idx] |
| 73 | + } |
| 74 | + return result |
67 | 75 | }
|
0 commit comments