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

Commit

Permalink
Make the create options configurable
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
pieterclaerhout committed May 28, 2020
1 parent e67771d commit 4deb7c4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ go-james new --path=<target path> \
--name=<name of your project> \
--description=<description of your project> \
--copyright=<copyright of your project> \
[--create-git-repo] \
[--with-git] \
[--overwrite]
```

Expand Down Expand Up @@ -175,7 +175,8 @@ You can specify the following options:
* `--name`: the name of the project, if not specified, the last part of the path is used
* `--description`: the description of the project, used for the readme
* `--copyright`: the copyright of the project, used for the readme
* `--create-git-repo`: if specified, a local Git repository will be created for the project and the source files will automatically be committed.
* `--with-git`: if specified, a local Git repository will be created for the project and the source files will automatically be committed.
* `--with-docker`: if specified, a sample Dockerfile and .dockerignore file will be created.
* `--overwrite`: if the destination path already exists, overwrite it (be careful, the original folder will be replaced)

## Initializing an existing project
Expand Down
31 changes: 20 additions & 11 deletions cmd/creator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ var NewCmd = climax.Command{
Variable: false,
},
{
Name: "create-git-repo",
Name: "with-git",
Short: "",
Usage: `--create-git-repo`,
Usage: `--with-git`,
Help: `Create a local git repository for this project`,
Variable: false,
},
{
Name: "with-docker",
Short: "",
Usage: `--with-docker`,
Help: `Create a sample Dockerfile`,
Variable: false,
},
},
Handle: func(ctx climax.Context) int {

Expand All @@ -70,17 +77,19 @@ var NewCmd = climax.Command{
description, _ := ctx.Get("description")
copyright, _ := ctx.Get("copyright")
overwrite := ctx.Is("overwrite")
createGitRepo := ctx.Is("create-git-repo")
withGit := ctx.Is("with-git")
withDocker := ctx.Is("with-docker")

tool := creator.Creator{
Mode: creator.NewProject,
Path: path,
Package: packageName,
Name: name,
Description: description,
Copyright: copyright,
Overwrite: overwrite,
CreateGitRepo: createGitRepo,
Mode: creator.NewProject,
Path: path,
Package: packageName,
Name: name,
Description: description,
Copyright: copyright,
Overwrite: overwrite,
WithGit: withGit,
WithDocker: withDocker,
}

executor := internal.NewExecutor("")
Expand Down
38 changes: 24 additions & 14 deletions internal/creator/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ type Creator struct {
common.Template
common.Logging

Mode Mode
Path string
Package string
Name string
Description string
Copyright string
Overwrite bool
CreateGitRepo bool
Mode Mode
Path string
Package string
Name string
Description string
Copyright string
Overwrite bool
WithGit bool
WithDocker bool
}

// Execute executes the command
Expand Down Expand Up @@ -106,16 +107,25 @@ func (creator Creator) Execute(project common.Project, cfg config.Config) error
creator.createVSCodeSettings,
creator.createLaunchConfig,
creator.createLicense,
creator.createGitIgnore,
creator.createDockerIgnore,
creator.createDockerFile,
creator.createReadme,
creator.createSourceFiles,
creator.createGoMod,
}

if creator.CreateGitRepo {
steps = append(steps, creator.createGitRepo)
if creator.WithDocker {
steps = append(
steps,
creator.createDockerIgnore,
creator.createDockerFile,
)
}

if creator.WithGit {
steps = append(
steps,
creator.createGitIgnore,
creator.createGitRepo,
)
}

for _, step := range steps {
Expand Down Expand Up @@ -185,7 +195,7 @@ func (creator Creator) createConfig(project common.Project, cfg config.Config) e

func (creator Creator) createTasks(project common.Project, cfg config.Config) error {

tasks := newVisualStudioCodeTaskList(cfg, creator.CreateGitRepo)
tasks := newVisualStudioCodeTaskList(cfg, creator.WithGit)

tasksPath := project.RelPath(visualStudioDirName, visualStudioCodeTasksFileName)
return creator.WriteJSONFileIfNotExists(tasksPath, tasks)
Expand Down

0 comments on commit 4deb7c4

Please sign in to comment.