Skip to content

Commit 8f922cb

Browse files
committed
clean comments
1 parent c1d2559 commit 8f922cb

File tree

3 files changed

+3
-36
lines changed

3 files changed

+3
-36
lines changed

cmd/add.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ nitric add website my-site astro`,
6565
return fmt.Errorf("non-interactive mode is not supported by this command")
6666
}
6767

68-
// get base url path for the website
6968
websitePath, err := cmd.Flags().GetString("path")
7069
if err != nil {
7170
return fmt.Errorf("failed to get path flag: %w", err)
@@ -87,14 +86,11 @@ nitric add website my-site astro`,
8786
Args: cobra.MaximumNArgs(2),
8887
}
8988

90-
// init registers the 'add' command with the root command
9189
func init() {
9290
rootCmd.AddCommand(addCmd)
9391

94-
// Add subcommands under 'add'
9592
addCmd.AddCommand(addWebsiteCmd)
9693

97-
// Copy and add the stack new command under 'add'
9894
addStackCmd := &cobra.Command{
9995
Use: "stack [stackName] [providerName]",
10096
Short: newStackCmd.Short,
@@ -105,6 +101,5 @@ func init() {
105101
addStackCmd.Flags().AddFlagSet(newStackCmd.Flags())
106102
addCmd.AddCommand(addStackCmd)
107103

108-
// Add flag for --path, the base url path for the website
109104
addWebsiteCmd.Flags().StringP("path", "p", "", "base url path for the website, e.g. /my-site")
110105
}

pkg/view/tui/commands/website/new.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ const (
5050
StepDone
5151
)
5252

53-
// Args holds the arguments required for the website project creation
5453
type Args struct {
5554
WebsiteName string
5655
WebsitePath string
5756
ToolName string
5857
}
5958

60-
var packageManagers = []string{"npm", "yarn", "pnpm"} // We will filter this based on what's installed
59+
var packageManagers = []string{"npm", "yarn", "pnpm"}
6160

6261
type configUpdatedResultMsg struct {
6362
err error
@@ -89,41 +88,33 @@ func New(fs afero.Fs, args Args) (Model, error) {
8988
config, err := project.ConfigurationFromFile(fs, "")
9089
tui.CheckErr(err)
9190

92-
// collect existing website names
9391
existingNames := []string{}
9492
for _, website := range config.Websites {
9593
existingNames = append(existingNames, website.Basedir)
9694
}
9795

98-
// If website name is provided in args, validate it first
9996
if args.WebsiteName != "" {
100-
// Normalize the provided name
10197
normalizedName := strings.TrimPrefix(args.WebsiteName, "./")
10298

103-
// Check if it's a duplicate
10499
for _, name := range existingNames {
105100
existingName := strings.TrimPrefix(name, "./")
106101
if existingName == normalizedName {
107102
return Model{}, fmt.Errorf("website name '%s' already exists", normalizedName)
108103
}
109104
}
110105

111-
// Validate the format
112106
if !WebsiteNameRegex.MatchString(normalizedName) {
113107
return Model{}, fmt.Errorf("website name can only contain letters, numbers, underscores and hyphens")
114108
}
115109

116-
// Check if name starts with a valid character
117110
if !WebsiteNameStartRegex.MatchString(normalizedName) {
118111
return Model{}, fmt.Errorf("website name must start with a letter or number")
119112
}
120113

121-
// Check if name ends with a valid character
122114
if !WebsiteNameEndRegex.MatchString(normalizedName) {
123115
return Model{}, fmt.Errorf("website name cannot end with a hyphen")
124116
}
125117

126-
// Check if directory already exists
127118
if _, err := fs.Stat(normalizedName); err == nil {
128119
return Model{}, fmt.Errorf("website directory '%s' already exists", normalizedName)
129120
} else if !os.IsNotExist(err) {
@@ -142,7 +133,6 @@ func New(fs afero.Fs, args Args) (Model, error) {
142133
InFlightValidator: nameInFlightValidator,
143134
})
144135

145-
// collect existing paths
146136
existingPaths := []string{}
147137

148138
for _, website := range config.Websites {
@@ -187,7 +177,6 @@ func New(fs afero.Fs, args Args) (Model, error) {
187177
if pathInUse {
188178
return Model{}, fmt.Errorf("path %s is already in use", args.WebsitePath)
189179
}
190-
// check if the path is valid
191180
if err := pathValidator(args.WebsitePath); err != nil {
192181
return Model{}, fmt.Errorf("path %s is invalid: %w", args.WebsitePath, err)
193182
}
@@ -286,7 +275,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
286275
m.packagePrompt.SetMaxDisplayedItems(m.windowSize.Height - 1)
287276
} else {
288277
m.toolPrompt.SetMinimized(false)
289-
maxItems := ((m.windowSize.Height - 3) / 3) // make room for the exit message
278+
maxItems := ((m.windowSize.Height - 3) / 3)
290279
m.toolPrompt.SetMaxDisplayedItems(maxItems)
291280
m.packagePrompt.SetMinimized(false)
292281
m.packagePrompt.SetMaxDisplayedItems(maxItems)
@@ -315,7 +304,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
315304
m.portPrompt.Blur()
316305
m.step = StepRunningToolCommand
317306

318-
// Run the command directly
319307
return m, m.runCommand()
320308
}
321309

@@ -339,7 +327,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
339327
return m, teax.Quit
340328
}
341329

342-
// Command completed successfully, update config
343330
return m, m.updateConfig()
344331
}
345332

@@ -359,7 +346,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
359346
return m, teax.Quit
360347
}
361348

362-
// if the tool is not package manager based, we need to run the command
363349
if tool.SkipPackageManagerPrompt {
364350
m.packagePrompt.SetChoice(tool.Value)
365351
m.step = StepPort
@@ -467,7 +453,6 @@ func (m Model) View() string {
467453
return v.Render()
468454
}
469455

470-
// help to get the selected tool
471456
func (m Model) getSelectedTool() (Tool, error) {
472457
tool, ok := lo.Find(tools, func(f Tool) bool {
473458
return f.Name == m.toolPrompt.Choice()
@@ -486,7 +471,6 @@ func (m Model) runCommand() tea.Cmd {
486471
return teax.Quit
487472
}
488473

489-
// if the tool has skip package manager prompt, check the tool exists and print the install guide
490474
if tool.SkipPackageManagerPrompt {
491475
if _, err := exec.LookPath(tool.Value); err != nil {
492476
return func() tea.Msg {
@@ -505,14 +489,11 @@ func (m Model) runCommand() tea.Cmd {
505489

506490
c := exec.Command(command, args...)
507491

508-
// Return a command that will execute the process
509492
return tea.ExecProcess(c, func(err error) tea.Msg {
510-
// If there was an error running the command
511493
if err != nil {
512494
return commandResultMsg{err: fmt.Errorf("failed to run website command: %w", err), msg: "Failed to create website"}
513495
}
514496

515-
// Check if the website directory was created
516497
websiteDir := m.namePrompt.Value()
517498
if _, err := m.fs.Stat(websiteDir); err != nil {
518499
if os.IsNotExist(err) {
@@ -522,12 +503,10 @@ func (m Model) runCommand() tea.Cmd {
522503
return commandResultMsg{err: fmt.Errorf("failed to check website directory: %w", err), msg: "Failed to verify website creation"}
523504
}
524505

525-
// If we get here, the website was created successfully
526506
return commandResultMsg{msg: "Website created successfully"}
527507
})
528508
}
529509

530-
// update the nitric.yaml config file with website
531510
func (m Model) updateConfig() tea.Cmd {
532511
return func() tea.Msg {
533512
var tool Tool
@@ -563,7 +542,6 @@ func (m Model) updateConfig() tea.Cmd {
563542
}
564543
}
565544

566-
// getAvailablePackageManagers filters package managers that exist on the system
567545
func getAvailablePackageManagers() []string {
568546
available := []string{}
569547

pkg/view/tui/commands/website/toolsetup.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ type CommandVars struct {
5151
}
5252

5353
func (f Tool) GetDevCommand(packageManager string, port string) string {
54-
// if packageManager is npm, we need to add run to the command
5554
if packageManager == "npm" {
5655
packageManager = "npm run"
5756
}
@@ -65,7 +64,6 @@ func (f Tool) GetDevCommand(packageManager string, port string) string {
6564
}
6665

6766
func (f Tool) GetBuildCommand(packageManager string, path string) string {
68-
// if packageManager is npm, we need to add run to the command
6967
if packageManager == "npm" {
7068
packageManager = "npm run"
7169
}
@@ -115,18 +113,14 @@ func (t CommandTemplate) Format(vars CommandVars) string {
115113
cmd = strings.ReplaceAll(cmd, "{port}", vars.Port)
116114
cmd = strings.ReplaceAll(cmd, "{baseURL}", vars.BaseURL)
117115

118-
// if the package manager is npm and using a run command,
119-
// we need to add a " -- " before the flags if it does not already exist
120116
if vars.PackageManager == "npm run" {
121-
// Find the first flag (starts with --)
122117
parts := strings.Split(cmd, " ")
123118
for i, part := range parts {
124119
if part == "--" {
125-
break // already has --
120+
break
126121
}
127122

128123
if strings.HasPrefix(part, "--") {
129-
// Insert " -- " before the first flag
130124
parts = append(parts[:i], append([]string{"--"}, parts[i:]...)...)
131125
cmd = strings.Join(parts, " ")
132126

0 commit comments

Comments
 (0)