-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from dung13890/develop
refs #init yml
- Loading branch information
Showing
13 changed files
with
175 additions
and
38 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/dung13890/deploy-tool/config" | ||
"github.com/fatih/color" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"text/template" | ||
) | ||
|
||
type answers struct { | ||
Project string | ||
Ip string | ||
Repo string | ||
} | ||
|
||
func NewInit() *cli.Command { | ||
return &cli.Command{ | ||
Name: "init", | ||
Aliases: []string{"i"}, | ||
Usage: "Setup new project", | ||
Action: func(ctx *cli.Context) error { | ||
a := &answers{} | ||
if err := a.exec(); err != nil { | ||
log.Fatal(err) | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (a *answers) exec() error { | ||
// Create question setup yml file | ||
qs := []*survey.Question{ | ||
{ | ||
Name: "project", | ||
Prompt: &survey.Input{Message: "Please setup project name:"}, | ||
Validate: survey.Required, | ||
}, | ||
{ | ||
Name: "ip", | ||
Prompt: &survey.Input{ | ||
Message: "Please setup IP Remote:", | ||
Default: "127.0.0.1", | ||
}, | ||
}, | ||
{ | ||
Name: "repo", | ||
Prompt: &survey.Input{ | ||
Message: "Please setup url repository:", | ||
Default: "git@github.com:repo/example.git", | ||
}, | ||
}, | ||
} | ||
|
||
if err := survey.Ask(qs, a); err != nil { | ||
return err | ||
} | ||
|
||
if err := a.createFile(a.Project); err != nil { | ||
return err | ||
} | ||
|
||
success := color.New(color.FgHiGreen, color.Bold).PrintlnFunc() | ||
success(fmt.Sprintf("Successfully generate file %s.yml", a.Project)) | ||
|
||
return nil | ||
} | ||
|
||
func (a *answers) createFile(filename string) (err error) { | ||
// Get Current path | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
return | ||
} | ||
|
||
filename = fmt.Sprintf("%s.yml", filename) | ||
|
||
// Check exists file config | ||
if _, err := os.Stat(filepath.Join(dir, filename)); err == nil || os.IsExist(err) { | ||
return errors.New(fmt.Sprintf("Warning: File config %s is exists.", filename)) | ||
} | ||
// Create File config yml | ||
f, err := os.Create(filepath.Join(dir, filename)) | ||
defer f.Close() | ||
if err != nil { | ||
return | ||
} | ||
// Parse template to template yml | ||
t, err := template.New("index").Parse(config.SourceYaml) | ||
if err != nil { | ||
return | ||
} | ||
t.Execute(f, a) | ||
|
||
return nil | ||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
var SourceYaml = `server: | ||
address: "{{ .Ip }}" | ||
user: "ec2-user" | ||
port: 22 | ||
dir: "/data/sites" | ||
project: "{{ .Project }}" | ||
repository: | ||
url: "{{ .Repo }}" | ||
branch: "master" | ||
# tag: "1.0.2" | ||
shared: | ||
folders: | ||
- "vendor" | ||
- "node_modules" | ||
files: | ||
- ".env" | ||
tasks: | ||
- "echo 'Hello!!'" | ||
cluster: | ||
hosts: | ||
# - "127.0.0.1" | ||
rsync: | ||
excludes: | ||
- ".env" | ||
- "*.log" | ||
cmds: | ||
- "uname -a" | ||
` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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