-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
746 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
cmd/golang/golang_cli/golang_cli_content_files/ci_github_files.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package golang_cli_content_files | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
func CreateCIGithubFiles(projectName string) { | ||
err := os.Mkdir(projectName + "/.github", os.FileMode(0777)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = os.Mkdir(projectName + "/.github/workflows", os.FileMode(0777)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writeGithubWorkflowFile(projectName) | ||
|
||
|
||
} | ||
|
||
func writeGithubWorkflowFile(projectName string){ | ||
var content = `name: goreleaser | ||
on: | ||
push: | ||
tags: | ||
- '*' | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN_GO_RELEASE }} | ||
` | ||
|
||
file, err := os.Create(projectName + "/.github/workflows/release.yml") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
_, err = file.WriteString(content) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
cmd/golang/golang_cli/golang_cli_content_files/cli_files.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package golang_cli_content_files | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
func CreateCLIPackage(projectName string) { | ||
err := os.Mkdir(projectName + "/cli", os.FileMode(0777)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writeCLISelectorFile(projectName) | ||
writeUserInputFile(projectName) | ||
|
||
|
||
} | ||
|
||
func writeCLISelectorFile(projectName string){ | ||
var content = `package cli | ||
import ( | ||
"github.com/manifoldco/promptui" | ||
"log" | ||
) | ||
// SelectorCli helps to get user input showing a selector with the passed options and label. | ||
func SelectorCli(label string, options ...string) (string, error) { | ||
s := promptui.Select{ | ||
Label: label, | ||
Items: options, | ||
} | ||
_, result, err := s.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return result, nil | ||
} | ||
` | ||
|
||
file, err := os.Create(projectName + "/cli/selector_cli.go") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
_, err = file.WriteString(content) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func writeUserInputFile(projectName string){ | ||
var content = `package cli | ||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/manifoldco/promptui" | ||
) | ||
// An example of validate function: | ||
// | ||
// validate := func(input string) error { | ||
// _, err := strconv.ParseFloat(input, 64) | ||
// if err != nil { | ||
// return errors.New("Invalid number") | ||
// } | ||
// return nil | ||
// } | ||
// UserInput allow to get the user input with optional validate function. | ||
func UserInput(label string, validate ...promptui.ValidateFunc) (string, error){ | ||
var validation promptui.ValidateFunc | ||
if len(validate) == 0 { | ||
validation = promptui.ValidateFunc(func(s string) error { | ||
return nil | ||
}) | ||
} else if len(validate) == 1 { | ||
validation = validate[0] | ||
} else if len(validate) > 1 { | ||
return "", errors.New("it's permited only one validation function parameter.") | ||
} | ||
prompt := promptui.Prompt{ | ||
Label: label, | ||
Validate: validation, | ||
} | ||
result, err := prompt.Run() | ||
if err != nil { | ||
fmt.Printf("Prompt failed %v\n", err) | ||
return "", err | ||
} | ||
return result, nil | ||
} | ||
` | ||
|
||
file, err := os.Create(projectName + "/cli/user_input.go") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
_, err = file.WriteString(content) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.