This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
generated from gleich/go_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
66 lines (60 loc) 路 1.94 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package commands
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/gleich/statuser/v2"
"github.com/gleich/texsch/pkg/commands/create"
"github.com/gleich/texsch/pkg/config"
"github.com/gleich/texsch/pkg/location"
"github.com/gleich/texsch/pkg/utils"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a document",
Run: func(cmd *cobra.Command, args []string) {
location.ChdirProjectRoot()
classes := config.ClassNames(config.Read())
if utils.GetBoolFlag(cmd, "classes") {
for _, class := range classes {
fmt.Println(class)
}
os.Exit(0)
}
if utils.GetBoolFlag(cmd, "doctypes") {
for _, docType := range create.DocumentTypes {
fmt.Println(docType)
}
os.Exit(0)
}
if utils.GetBoolFlag(cmd, "templates") {
files, err := ioutil.ReadDir("./texsch/templates")
if err != nil {
statuser.Error("Failed to get a list of all the templates", err, 1)
}
for _, file := range files {
if !file.IsDir() {
fmt.Println(strings.TrimSuffix(file.Name(), ".txt"))
}
}
os.Exit(0)
}
path := create.Document(cmd, classes)
create.Post(cmd, path)
},
}
func init() {
createCmd.Flags().StringP("name", "n", "", "Name of the document")
createCmd.Flags().StringP("type", "t", "", "Document type (e.g. Worksheet)")
createCmd.Flags().StringP("class", "c", "", "Class name for the document (e.g. Physics)")
createCmd.Flags().String("template", "", "Template for the document")
createCmd.Flags().Bool("classes", false, "Output the user's classes")
createCmd.Flags().Bool("doctypes", false, "Output the available document types")
createCmd.Flags().Bool("templates", false, "Output the available templates")
createCmd.Flags().Bool("no-clipboard", false, "If the clipboard configuration should be ignored")
createCmd.Flags().Bool("no-editor", false, "If the editor configuration should be ignored")
rootCmd.AddCommand(createCmd)
}