mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
+15
-15
@@ -6,19 +6,19 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/coder/coder/cli/clibase"
|
||||
"github.com/coder/coder/cli/cliui"
|
||||
"github.com/coder/coder/codersdk"
|
||||
"github.com/coder/coder/examples"
|
||||
"github.com/coder/coder/provisionersdk"
|
||||
)
|
||||
|
||||
func templateInit() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "init [directory]",
|
||||
Short: "Get started with a templated template.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
func (*RootCmd) templateInit() *clibase.Cmd {
|
||||
return &clibase.Cmd{
|
||||
Use: "init [directory]",
|
||||
Short: "Get started with a templated template.",
|
||||
Middleware: clibase.RequireRangeArgs(0, 1),
|
||||
Handler: func(inv *clibase.Invocation) error {
|
||||
exampleList, err := examples.List()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -36,10 +36,10 @@ func templateInit() *cobra.Command {
|
||||
exampleByName[name] = example
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Wrap.Render(
|
||||
_, _ = fmt.Fprintln(inv.Stdout, cliui.Styles.Wrap.Render(
|
||||
"A template defines infrastructure as code to be provisioned "+
|
||||
"for individual developer workspaces. Select an example to be copied to the active directory:\n"))
|
||||
option, err := cliui.Select(cmd, cliui.SelectOptions{
|
||||
option, err := cliui.Select(inv, cliui.SelectOptions{
|
||||
Options: exampleNames,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -55,8 +55,8 @@ func templateInit() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
var directory string
|
||||
if len(args) > 0 {
|
||||
directory = args[0]
|
||||
if len(inv.Args) > 0 {
|
||||
directory = inv.Args[0]
|
||||
} else {
|
||||
directory = filepath.Join(workingDir, selectedTemplate.ID)
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func templateInit() *cobra.Command {
|
||||
} else {
|
||||
relPath = "./" + relPath
|
||||
}
|
||||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Extracting %s to %s...\n", cliui.Styles.Field.Render(selectedTemplate.ID), relPath)
|
||||
_, _ = fmt.Fprintf(inv.Stdout, "Extracting %s to %s...\n", cliui.Styles.Field.Render(selectedTemplate.ID), relPath)
|
||||
err = os.MkdirAll(directory, 0o700)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -75,9 +75,9 @@ func templateInit() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Create your template by running:")
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render(cliui.Styles.Code.Render("cd "+relPath+" && coder templates create"))+"\n")
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Wrap.Render("Examples provide a starting point and are expected to be edited! 🎨"))
|
||||
_, _ = fmt.Fprintln(inv.Stdout, "Create your template by running:")
|
||||
_, _ = fmt.Fprintln(inv.Stdout, cliui.Styles.Paragraph.Render(cliui.Styles.Code.Render("cd "+relPath+" && coder templates create"))+"\n")
|
||||
_, _ = fmt.Fprintln(inv.Stdout, cliui.Styles.Wrap.Render("Examples provide a starting point and are expected to be edited! 🎨"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user