Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve cmd[run/new] #116

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading