Skip to content

Commit

Permalink
Merge pull request #193 from zeabur/pan93412/ZEA-2448-submodule-name
Browse files Browse the repository at this point in the history
ZEA-2448: Customizable submodule name in CLI
  • Loading branch information
Yuanlin Lin authored Jan 19, 2024
2 parents 27e5362 + 052209d commit 39738a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/zbpack/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e

// GetSubmoduleName is used to get submodule name from path.
func GetSubmoduleName(path string) (submoduleName string, err error) {
if userSubmoduleName != "" {
return userSubmoduleName, nil
}

var absPath string
if strings.HasPrefix(path, "https://") {
absPath = path
Expand Down
12 changes: 9 additions & 3 deletions internal/zbpack/zbpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
"os/exec"
"strings"

"github.com/samber/lo"
"github.com/spf13/cobra"
"github.com/zeabur/zbpack/pkg/zeaburpack"
)

var (
// info option is used to analyze and print project information.
info bool
cmd = &cobra.Command{
// userSubmoduleName option is used to specify the submodule name of this project manually
userSubmoduleName string
cmd = &cobra.Command{
Use: "zbpack",
Short: "Zbpack is a tool to help you analyze your project and build Docker image in one click.",
Long: "Zbpack is a powerful tool that not only analyzes your project for dependencies and requirements, " +
Expand All @@ -34,6 +37,7 @@ var (

func init() {
cmd.PersistentFlags().BoolVarP(&info, "info", "i", false, "only print project information")
cmd.PersistentFlags().StringVar(&userSubmoduleName, "submodule", "", "submodule (service) name. by default, it is picked from the directory name.")
cmd.SetUsageTemplate(usageTemplate)
}

Expand Down Expand Up @@ -87,12 +91,12 @@ func build(path string) error {
log.Fatalln(err)
}

trueValue := true
log.Printf("using submoduleName: %s", submoduleName)

return zeaburpack.Build(
&zeaburpack.BuildOptions{
Path: &path,
Interactive: &trueValue,
Interactive: lo.ToPtr(true),
SubmoduleName: &submoduleName,
},
)
Expand All @@ -105,6 +109,8 @@ func plan(path string) error {
log.Fatalln(err)
}

log.Printf("using submoduleName: %s", submoduleName)

githubToken := os.Getenv("GITHUB_ACCESS_TOKEN")
if strings.HasPrefix(path, "https://github.com") && githubToken == "" {
return fmt.Errorf("GITHUB_ACCESS_TOKEN is required for GitHub URL")
Expand Down

0 comments on commit 39738a4

Please sign in to comment.