-
Notifications
You must be signed in to change notification settings - Fork 3
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
Paul Lhussiez
committed
Apr 15, 2019
1 parent
aa70272
commit 56530a2
Showing
6 changed files
with
119 additions
and
30 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,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/AlecAivazis/survey.v1" | ||
|
||
_ "github.com/Depado/quokka/conf" // Import conf to ensure package init for survey | ||
"github.com/Depado/quokka/utils" | ||
) | ||
|
||
// NewQuokkaTemplate will create a new Quokka template with default params | ||
func NewQuokkaTemplate(path string) { | ||
var err error | ||
|
||
if _, err = os.Stat(path); !os.IsNotExist(err) { | ||
var confirmed bool | ||
prompt := &survey.Confirm{ | ||
Message: "The output destination already exists. Continue ?", | ||
} | ||
survey.AskOne(prompt, &confirmed, nil) // nolint: errcheck | ||
if !confirmed { | ||
utils.ErrPrintln("Canceled operation") | ||
os.Exit(0) | ||
} | ||
} else { | ||
if err = os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { | ||
utils.FatalPrintln("Unable to create directory") | ||
} | ||
} | ||
var qs = []*survey.Question{ | ||
{ | ||
Name: "name", | ||
Prompt: &survey.Input{ | ||
Message: "Name of the template?", | ||
Default: "Quokka Template", | ||
}, | ||
}, | ||
{ | ||
Name: "description", | ||
Prompt: &survey.Input{ | ||
Message: "Description of the template?", | ||
Default: "New Quokka Template", | ||
}, | ||
}, | ||
{ | ||
Name: "version", | ||
Prompt: &survey.Input{ | ||
Message: "Version of the template?", | ||
Default: "0.1.0", | ||
}, | ||
}, | ||
} | ||
answers := struct { | ||
Name string // survey will match the question and field names | ||
Description string `survey:"color"` // or you can tag fields to match a specific name | ||
Version int // if the types don't match exactly, survey will try to convert for you | ||
}{} | ||
|
||
// perform the questions | ||
if err = survey.Ask(qs, &answers); err != nil { | ||
utils.FatalPrintln("Unable to ask questions") | ||
} | ||
|
||
fmt.Println(answers) | ||
} |
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