Skip to content

Commit

Permalink
chore: imporve cmd[run/new] (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
qloog authored Nov 19, 2023
1 parent c54a6f1 commit e2ac650
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- chore(cli): improve gen task command
- chore(response): remove init resp and improve Error
- chore: improve redis queue and add example
- chore: improve cmd: new and run

## v1.7.0
- feat(http): can custom http status
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ eagle new github.com/foo/eagle-demo
make build

# run
./eagle-demo
eagle run
```

## Documentation
Expand Down
4 changes: 2 additions & 2 deletions cmd/eagle/internal/project/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (p *Project) New(ctx context.Context, dir string, layout string) error {
fmt.Print("💻 Use the following command to start the project 👇:\n\n")

fmt.Println(color.WhiteString("$ cd %s", p.Name))
fmt.Println(color.WhiteString("$ go build"))
fmt.Println(color.WhiteString("$ ./%s\n", p.Name))
fmt.Println(color.WhiteString("$ make build"))
fmt.Println(color.WhiteString("$ eagle run\n"))
fmt.Println("🤝 Thanks for using Eagle")
fmt.Println("📚 Tutorial: https://go-eagle.org/docs/getting-started/start")
return nil
Expand Down
23 changes: 16 additions & 7 deletions cmd/eagle/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var CmdRun = &cobra.Command{
Run: Run,
}

// Run run project.
// Run project.
func Run(cmd *cobra.Command, args []string) {
var dir string
if len(args) > 0 {
Expand All @@ -32,6 +32,7 @@ func Run(cmd *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", err)
return
}
var selectedDir string
if dir == "" {
// find the directory containing the cmd/*
cmdPath, err := findCMD(base)
Expand All @@ -52,17 +53,24 @@ func Run(cmd *cobra.Command, args []string) {
cmdPaths = append(cmdPaths, k)
}
prompt := &survey.Select{
Message: "Which directory do you want to run?",
Options: cmdPaths,
Message: "Which directory do you want to run?",
Options: cmdPaths,
PageSize: 6,
}
survey.AskOne(prompt, &dir)
if dir == "" {
// get cmd dir, eg: cmd/server
err := survey.AskOne(prompt, &dir)
if err != nil && dir == "" {
return
}
dir = path.Join(cmdPath[dir], dir)
// eg: cmd/server
selectedDir = dir
// project absolute path
dir = cmdPath[dir]
}
}
fd := exec.Command("go", "run", ".")

// go run /path/cmd/server
fd := exec.Command("go", []string{"run", path.Join(dir, selectedDir)}...)
fd.Stdout = os.Stdout
fd.Stderr = os.Stderr
fd.Dir = dir
Expand All @@ -73,6 +81,7 @@ func Run(cmd *cobra.Command, args []string) {
return
}

// map, eg: cmd/server -> project absolute path
func findCMD(base string) (map[string]string, error) {
var root bool
next := func(dir string) (map[string]string, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/eagle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var (
// Version is the version of the compiled software.
Version = "v0.15.6"
Version = "v0.16.0"

rootCmd = &cobra.Command{
Use: "eagle",
Expand Down

0 comments on commit e2ac650

Please sign in to comment.