Skip to content

Commit

Permalink
enable setting template in init
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Aug 27, 2021
1 parent 011f41a commit b179cc9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
/cmd/mantil/mantil-amd
4 changes: 3 additions & 1 deletion cmd/mantil/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ var initCmd = &cobra.Command{
log.Fatalf("could not prompt project name - %v", err)
}
noRepo, _ := cmd.Flags().GetBool("no-repo")
template := cmd.Flag("template").Value.String()
var githubOrg string
if !noRepo {
githubOrg, err = promptGithubOrganization()
if err != nil {
log.Fatalf("could not prompt github organization - %v", err)
}
}
i, err := initialize.New(projectName, githubOrg, noRepo)
i, err := initialize.New(projectName, githubOrg, noRepo, template)
if err != nil {
log.Fatal(err)
}
Expand All @@ -51,5 +52,6 @@ func promptGithubOrganization() (string, error) {

func init() {
initCmd.Flags().Bool("no-repo", false, "Skip creating a github repository for the project")
initCmd.Flags().StringP("template", "t", "", "project template name, one of: ping, excuses")
rootCmd.AddCommand(initCmd)
}
24 changes: 22 additions & 2 deletions internal/commands/initialize/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ type InitCmd struct {
name string
noRepo bool
githubOrg string
template string
}

func New(name, githubOrg string, noRepo bool) (*InitCmd, error) {
func New(name, githubOrg string, noRepo bool, template string) (*InitCmd, error) {
return &InitCmd{
name: name,
noRepo: noRepo,
githubOrg: githubOrg,
template: template,
}, nil
}

func (i *InitCmd) InitProject() error {
templateRepo := i.templateRepo()
if templateRepo == "" {
return fmt.Errorf("unknown template %s, can be one of ping, excuses", i.template)
}

token, err := i.initRequest(i.name)
if err != nil || token == "" {
return fmt.Errorf("could not initialize project - %v", err)
Expand All @@ -34,7 +41,7 @@ func (i *InitCmd) InitProject() error {
if err != nil {
return fmt.Errorf("could not initialize github client - %v", err)
}
templateRepo := "https://github.com/mantil-io/go-mantil-template"

project, err := mantil.NewProject(i.name)
if err != nil {
return fmt.Errorf("could not create project %s - %v", i.name, err)
Expand All @@ -60,6 +67,19 @@ func (i *InitCmd) InitProject() error {
return nil
}

func (i *InitCmd) templateRepo() string {
ping := "https://github.com/mantil-io/go-mantil-template"
switch i.template {
case "excuses":
return "https://github.com/mantil-io/template-excuses"
case "ping":
return ping
case "":
return ping
}
return ""
}

func (i *InitCmd) initRequest(projectName string) (string, error) {
type initReq struct {
ProjectName string
Expand Down
3 changes: 3 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
root=$(git rev-parse --show-toplevel)

cd "$root/cmd/mantil"
GOOS=linux GOARCH=amd64 go build -o mantil-amd
aws s3 cp mantil-amd s3://mantil-downloads/mantil

go build
aws s3 cp mantil s3://mantil-downloads/mantil-osx

0 comments on commit b179cc9

Please sign in to comment.