Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Fix ProjectPathCommand consumedFlags if project path not set
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Aug 20, 2021
1 parent 7596017 commit bd52582
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func GenerateRunFunc(c Command) func(*cobra.Command, []string) error {
}
consumedFlags += consumed
}

// FIXME seed command doesn't work properly if project path isn't specified
if cmd.Flags().NFlag()-consumedFlags == 0 { // FIXME doesn't work if project-path is set
questions, err := c.BuildSurvey()
if err != nil {
Expand Down Expand Up @@ -78,30 +80,32 @@ type ProjectPathCommand struct {
}

// Setup ensure the `ProjectPath` field is correctly set.
// If `ProjectPath` is empty at the time `setup()` is called, its value
// If `ProjectPath` is empty at the time `Setup()` is called, its value
// will be set to `fs.FindParentModule()`.
// The project's `go.mod` file is parsed and put into the `GoyaveMod` field.
// The Goyave framework version is parsed and put into the `GoyaveVersion` field.
func (c *ProjectPathCommand) Setup() (int, error) {
consumedFlags := 1
if c.ProjectPath == "" {
consumedFlags = 0
c.ProjectPath = mod.FindParentModule()
if c.ProjectPath == "" {
return 1, mod.ErrNoGoMod
return consumedFlags, mod.ErrNoGoMod
}
}
modFile, err := mod.Parse(c.ProjectPath)
if err != nil {
return 1, err
return consumedFlags, err
}

c.GoyaveMod = mod.FindGoyaveRequire(modFile)
if c.GoyaveMod == nil {
return 1, mod.ErrNotAGoyaveProject
return consumedFlags, mod.ErrNotAGoyaveProject
}

c.GoyaveVersion, err = semver.NewVersion(c.GoyaveMod.Mod.Version)
if err != nil {
return 1, err
return consumedFlags, err
}
return 1, nil
return consumedFlags, nil
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func buildRootCommand() *cobra.Command {
gyv := &cobra.Command{
Use: "gyv",
Version: "0.1.0", // TODO use ldflags to set version at compile-time
Version: "0.2.1", // TODO use ldflags to set version at compile-time
Short: "Productivity CLI for the Goyave framework",
Long: `gyv productivity command-line interface for the Goyave framework.
All commands can be run either in interactive mode or using POSIX flags.`,
Expand Down

0 comments on commit bd52582

Please sign in to comment.