Skip to content

Commit ef21dc4

Browse files
authored
Merge pull request #16 from Kasui92/dev
lancher 0.2.1
2 parents 2590c27 + 45ad085 commit ef21dc4

11 files changed

Lines changed: 137 additions & 168 deletions

File tree

internal/cli/cli.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ func Run(args []string) error {
6262
usage := "USAGE:\n lancher template <SUBCOMMAND> [ARGS...] [OPTIONS]"
6363
return shared.FormatUnknownSubcommandError(subcommand, "lancher template", usage)
6464
}
65-
case "info":
65+
case "templates":
66+
// Alias for template ls
6667
// Check for help flag
6768
if len(commandArgs) > 0 && (commandArgs[0] == "help" || commandArgs[0] == "-h" || commandArgs[0] == "--help") {
68-
return commands.RunInfoHelp()
69+
return template.RunListHelp()
6970
}
70-
return commands.RunInfo(commandArgs)
71+
return template.RunList(commandArgs)
7172
case "upgrade":
7273
// Check for help flag
7374
if len(commandArgs) > 0 && (commandArgs[0] == "help" || commandArgs[0] == "-h" || commandArgs[0] == "--help") {
@@ -96,7 +97,7 @@ func runHelp() error {
9697
fmt.Printf("%sCOMMANDS:%s\n", shared.ColorCyan+shared.ColorBold, shared.ColorReset)
9798
fmt.Printf(" %s%-20s%s %s\n", shared.ColorGreen, "create", shared.ColorReset, "Create a new project from template")
9899
fmt.Printf(" %s%-20s%s %s\n", shared.ColorGreen, "template", shared.ColorReset, "Manage templates (add, list, update, remove)")
99-
fmt.Printf(" %s%-20s%s %s\n", shared.ColorGreen, "info", shared.ColorReset, "Show storage information")
100+
fmt.Printf(" %s%-20s%s %s\n", shared.ColorGreen, "templates", shared.ColorReset, "List all available templates")
100101
fmt.Printf(" %s%-20s%s %s\n", shared.ColorGreen, "upgrade", shared.ColorReset, "Check for updates and upgrade to latest version")
101102
fmt.Printf(" %shelp%s, %s-h%s %s\n\n", shared.ColorGreen, shared.ColorReset, shared.ColorGreen, shared.ColorReset, "Print this help message")
102103

internal/cli/commands/create.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ func Run(args []string) error {
4747
templateName = args[i+1]
4848
i++
4949
} else {
50-
return shared.FormatError("create", "flag -t/--template requires a value")
50+
return shared.FormatError("flag -t/--template requires a value")
5151
}
5252
case "-d", "--destination":
5353
if i+1 < len(args) {
5454
destination = args[i+1]
5555
i++
5656
} else {
57-
return shared.FormatError("create", "flag -d/--destination requires a value")
57+
return shared.FormatError("flag -d/--destination requires a value")
5858
}
5959
case "--git":
6060
gitInit = true
@@ -77,18 +77,18 @@ func Run(args []string) error {
7777

7878
// Validate mutually exclusive flags
7979
if gitInit && noGit {
80-
return shared.FormatError("create", "cannot use both --git and --no-git flags")
80+
return shared.FormatError("cannot use both --git and --no-git flags")
8181
}
8282
if executeHooks && noHooks {
83-
return shared.FormatError("create", "cannot use both --hooks and --no-hooks flags")
83+
return shared.FormatError("cannot use both --hooks and --no-hooks flags")
8484
}
8585

8686
// Interactive mode if flags not provided
8787
if templateName == "" {
8888
// List available templates
8989
templates, err := storage.ListTemplates()
9090
if err != nil {
91-
return shared.FormatError("create", fmt.Sprintf("failed to list templates: %v", err))
91+
return shared.FormatError(fmt.Sprintf("failed to list templates: %v", err))
9292
}
9393

9494
if len(templates) == 0 {
@@ -104,7 +104,7 @@ func Run(args []string) error {
104104
fmt.Printf("%sCancelled.%s\n", shared.ColorYellow, shared.ColorReset)
105105
return nil
106106
}
107-
return shared.FormatError("create", fmt.Sprintf("selection failed: %v", err))
107+
return shared.FormatError(fmt.Sprintf("selection failed: %v", err))
108108
}
109109
templateName = selectedTemplate
110110

@@ -119,24 +119,24 @@ func Run(args []string) error {
119119
fmt.Printf("%sCancelled.%s\n", shared.ColorYellow, shared.ColorReset)
120120
return nil
121121
}
122-
return shared.FormatError("create", "failed to read input")
122+
return shared.FormatError("failed to read input")
123123
}
124124
destination = dest
125125
fmt.Printf("%s✓ Destination set:%s %s\n", shared.ColorGreen, shared.ColorReset, destination)
126126
}
127127

128128
// Validate template name
129129
if err := shared.SanitizeTemplateName(templateName); err != nil {
130-
return shared.FormatError("create", err.Error())
130+
return shared.FormatError(err.Error())
131131
}
132132

133133
// Check if template exists
134134
exists, err := storage.TemplateExists(templateName)
135135
if err != nil {
136-
return shared.FormatError("create", fmt.Sprintf("failed to check template: %v", err))
136+
return shared.FormatError(fmt.Sprintf("failed to check template: %v", err))
137137
}
138138
if !exists {
139-
return shared.FormatError("create", fmt.Sprintf("template '%s' not found", templateName))
139+
return shared.FormatError(fmt.Sprintf("template '%s' not found", templateName))
140140
}
141141

142142
// Handle destination path resolution
@@ -146,35 +146,35 @@ func Run(args []string) error {
146146
if destination == "." {
147147
destAbs, err = os.Getwd()
148148
if err != nil {
149-
return shared.FormatError("create", fmt.Sprintf("failed to get current directory: %v", err))
149+
return shared.FormatError(fmt.Sprintf("failed to get current directory: %v", err))
150150
}
151151
} else {
152152
// Get absolute path
153153
destAbs, err = filepath.Abs(destination)
154154
if err != nil {
155-
return shared.FormatError("create", fmt.Sprintf("invalid destination path: %v", err))
155+
return shared.FormatError(fmt.Sprintf("invalid destination path: %v", err))
156156
}
157157
}
158158

159159
// Check if parent directory exists for nested paths
160160
parentDir := filepath.Dir(destAbs)
161161
if parentDir != "." && parentDir != "/" {
162162
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
163-
return shared.FormatError("create", fmt.Sprintf("parent directory does not exist: %s", parentDir))
163+
return shared.FormatError(fmt.Sprintf("parent directory does not exist: %s", parentDir))
164164
}
165165
}
166166

167167
// Check if destination already exists
168168
if stat, err := os.Stat(destAbs); err == nil {
169169
// Destination exists - check if it's a directory
170170
if !stat.IsDir() {
171-
return shared.FormatError("create", fmt.Sprintf("destination exists and is not a directory: %s", destAbs))
171+
return shared.FormatError(fmt.Sprintf("destination exists and is not a directory: %s", destAbs))
172172
}
173173

174174
// Check if directory is empty
175175
entries, err := os.ReadDir(destAbs)
176176
if err != nil {
177-
return shared.FormatError("create", fmt.Sprintf("failed to read destination directory: %v", err))
177+
return shared.FormatError(fmt.Sprintf("failed to read destination directory: %v", err))
178178
}
179179

180180
if len(entries) > 0 {
@@ -184,7 +184,7 @@ func Run(args []string) error {
184184

185185
confirmed, err := shared.PromptConfirmWithDefault("Do you want to remove and recreate the directory?", false)
186186
if err != nil {
187-
return shared.FormatError("create", "failed to read confirmation")
187+
return shared.FormatError("failed to read confirmation")
188188
}
189189

190190
if !confirmed {
@@ -194,7 +194,7 @@ func Run(args []string) error {
194194

195195
// Remove existing directory
196196
if err := os.RemoveAll(destAbs); err != nil {
197-
return shared.FormatError("create", fmt.Sprintf("failed to remove existing directory: %v", err))
197+
return shared.FormatError(fmt.Sprintf("failed to remove existing directory: %v", err))
198198
}
199199
fmt.Printf("%s✓ Removed existing directory%s\n", shared.ColorGreen, shared.ColorReset)
200200
}
@@ -203,13 +203,13 @@ func Run(args []string) error {
203203
// Get template path
204204
templatePath, err := storage.GetTemplatePath(templateName)
205205
if err != nil {
206-
return shared.FormatError("create", fmt.Sprintf("failed to get template path: %v", err))
206+
return shared.FormatError(fmt.Sprintf("failed to get template path: %v", err))
207207
}
208208

209209
// Load template configuration if exists
210210
cfg, err := config.LoadConfig(templatePath)
211211
if err != nil {
212-
return shared.FormatError("create", fmt.Sprintf("failed to load template config: %v", err))
212+
return shared.FormatError(fmt.Sprintf("failed to load template config: %v", err))
213213
}
214214

215215
// Display template metadata if available
@@ -236,7 +236,7 @@ func Run(args []string) error {
236236
if spinner != nil {
237237
spinner.Fail(fmt.Sprintf("Failed to create project: %v", err))
238238
}
239-
return shared.FormatError("create", fmt.Sprintf("failed to create project: %v", err))
239+
return shared.FormatError(fmt.Sprintf("failed to create project: %v", err))
240240
}
241241

242242
if spinner != nil {
@@ -266,7 +266,7 @@ func Run(args []string) error {
266266
var err error
267267
confirmed, err = shared.PromptConfirmWithDefault("Execute hooks?", true)
268268
if err != nil {
269-
return shared.FormatError("create", "failed to read confirmation")
269+
return shared.FormatError("failed to read confirmation")
270270
}
271271
}
272272

@@ -289,7 +289,7 @@ func Run(args []string) error {
289289
var err error
290290
gitInit, err = shared.PromptConfirmWithDefault("Initialize git repository?", false)
291291
if err != nil {
292-
return shared.FormatError("create", "failed to read confirmation")
292+
return shared.FormatError("failed to read confirmation")
293293
}
294294
}
295295

internal/cli/commands/info.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

internal/cli/commands/upgrade.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func RunUpgrade(args []string) error {
6060

6161
// Check if we're on a supported platform
6262
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
63-
return shared.FormatError("upgrade", "upgrade is only supported on Linux and macOS")
63+
return shared.FormatError("upgrade is only supported on Linux and macOS")
6464
}
6565

6666
currentVersion := version.Get()
@@ -77,7 +77,7 @@ func RunUpgrade(args []string) error {
7777
latestRelease, err := getLatestRelease()
7878
if err != nil {
7979
spinner.Fail("Failed to check for updates")
80-
return shared.FormatError("upgrade", fmt.Sprintf("failed to check for updates: %v", err))
80+
return shared.FormatError(fmt.Sprintf("failed to check for updates: %v", err))
8181
}
8282

8383
latestVersion := strings.TrimPrefix(latestRelease.TagName, "v")
@@ -104,13 +104,13 @@ func RunUpgrade(args []string) error {
104104
if force {
105105
conf, err := shared.PromptConfirmWithDefault(fmt.Sprintf("Reinstall version %s?", latestVersion), false)
106106
if err != nil {
107-
return shared.FormatError("upgrade", "failed to read confirmation")
107+
return shared.FormatError("failed to read confirmation")
108108
}
109109
confirmed = conf
110110
} else {
111111
conf, err := shared.PromptConfirmWithDefault(fmt.Sprintf("Upgrade to version %s?", latestVersion), false)
112112
if err != nil {
113-
return shared.FormatError("upgrade", "failed to read confirmation")
113+
return shared.FormatError("failed to read confirmation")
114114
}
115115
confirmed = conf
116116
}
@@ -127,7 +127,7 @@ func RunUpgrade(args []string) error {
127127
script, err := downloadInstallScript()
128128
if err != nil {
129129
upgradeSpinner.Fail("Failed to download installer")
130-
return shared.FormatError("upgrade", fmt.Sprintf("failed to download installer: %v", err))
130+
return shared.FormatError(fmt.Sprintf("failed to download installer: %v", err))
131131
}
132132

133133
upgradeSpinner.Stop()
@@ -141,7 +141,7 @@ func RunUpgrade(args []string) error {
141141
cmd.Stdin = os.Stdin
142142

143143
if err := cmd.Run(); err != nil {
144-
return shared.FormatError("upgrade", fmt.Sprintf("installation failed: %v", err))
144+
return shared.FormatError(fmt.Sprintf("installation failed: %v", err))
145145
}
146146

147147
fmt.Printf("\n%s✓ Upgrade completed successfully%s\n", shared.ColorGreen, shared.ColorReset)

internal/cli/shared/utils.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"strings"
77
)
88

9-
// FormatError creates a user-friendly error message
10-
func FormatError(cmd string, message string) error {
11-
return fmt.Errorf("%s: %s", cmd, message)
9+
// FormatError creates a user-friendly error message with visual styling
10+
func FormatError(message string) error {
11+
return fmt.Errorf("%s✗%s %s", ColorRed, ColorReset, message)
1212
}
1313

1414
// CommandExists checks if a command is available in PATH
@@ -19,18 +19,20 @@ func CommandExists(cmd string) bool {
1919

2020
// FormatUnknownCommandError creates a formatted error for unknown commands
2121
func FormatUnknownCommandError(arg string, usage string, helpCmd string) error {
22-
return fmt.Errorf("%sError:%s Unknown command '%s%s%s'\n\n%s\n\nRun %s--help%s for more information",
23-
ColorRed+ColorBold, ColorReset,
22+
return fmt.Errorf("%sUnknown command '%s%s%s'%s\n\n%s\n\nRun %s--help%s for more information",
23+
ColorRed+ColorBold,
2424
ColorYellow, arg, ColorReset,
25+
ColorReset,
2526
usage,
2627
ColorGreen, ColorReset)
2728
}
2829

2930
// FormatUnknownSubcommandError creates a formatted error for unknown subcommands
3031
func FormatUnknownSubcommandError(arg string, parentCmd string, usage string) error {
31-
return fmt.Errorf("%sError:%s Unknown subcommand '%s%s%s'\n\n%s\n\nRun %s%s --help%s for more information",
32-
ColorRed+ColorBold, ColorReset,
32+
return fmt.Errorf("%sUnknown subcommand '%s%s%s'%s\n\n%s\n\nRun %s%s --help%s for more information",
33+
ColorRed+ColorBold,
3334
ColorYellow, arg, ColorReset,
35+
ColorReset,
3436
usage,
3537
ColorGreen, parentCmd, ColorReset)
3638
}
@@ -63,7 +65,7 @@ func FormatMissingArgsError(missingArgs []string, usage string) error {
6365
argsText = strings.TrimSuffix(argsText, "\n")
6466
}
6567

66-
return fmt.Errorf("%sError:%s The following required arguments were not provided:\n%s\n\n%s\n\nRun %s--help%s for more information",
68+
return fmt.Errorf("%sThe following required arguments were not provided:%s\n%s\n\n%s\n\nRun %s--help%s for more information",
6769
ColorRed+ColorBold, ColorReset,
6870
argsText,
6971
usage,

0 commit comments

Comments
 (0)