-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (79 loc) · 2.9 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"os"
"github.com/aevea/oto-tools/internal/generaterunner"
"github.com/aevea/oto-tools/internal/npm"
"github.com/aevea/oto-tools/internal/publishrunner"
"github.com/aevea/oto-tools/internal/versioning"
"github.com/spf13/cobra"
)
func main() {
var rootCmd = &cobra.Command{
Use: "oto-tools",
Short: "Tooling for the great oto lib",
Long: "Tooling for the great oto lib",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Print("There is no root command. Please check oto-tools --help.")
return nil
},
SilenceUsage: true,
SilenceErrors: true,
}
var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generates package json",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
runner := generaterunner.Runner{}
path := cmd.Flag("path").Value.String()
packageName := cmd.Flag("package-name").Value.String()
packageVersion := cmd.Flag("package-version").Value.String()
otoTemplate := cmd.Flag("oto-template").Value.String()
otoDefinitions := cmd.Flag("oto-definitions").Value.String()
if packageVersion == "" {
packageVersion = versioning.FindVersion()
}
return runner.Run(
path,
npm.Package{Name: packageName, Version: packageVersion},
generaterunner.OtoOptions{TemplatePath: otoTemplate, DefinitionPath: otoDefinitions},
)
},
}
generateCmd.PersistentFlags().String("path", "./js", "set path for output of package.json")
generateCmd.PersistentFlags().String("package-name", "", "set name of project in package.json")
generateCmd.PersistentFlags().String("package-version", "", "set version of project in package.json")
generateCmd.PersistentFlags().String("oto-template", "", "path to oto template")
generateCmd.PersistentFlags().String("oto-definitions", "", "path to oto definition")
rootCmd.AddCommand(generateCmd)
var NPMPublishCmd = &cobra.Command{
Use: "publish-npm",
Short: "Publishes provided package to NPM",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
runner := publishrunner.Runner{}
path := cmd.Flag("path").Value.String()
token := cmd.Flag("token").Value.String()
registry := cmd.Flag("registry").Value.String()
owner := cmd.Flag("owner").Value.String()
return runner.Run(
path,
npm.PublishOptions{
Token: token,
RegistryURL: registry,
Owner: owner,
},
)
},
}
NPMPublishCmd.PersistentFlags().String("path", "./js", "set path for js library to publish")
NPMPublishCmd.PersistentFlags().String("token", "", "token for authenticating against NPM")
NPMPublishCmd.PersistentFlags().String("registry", "", "NPM compatible registry to publish to, accepts npm, github, or url")
NPMPublishCmd.PersistentFlags().String("owner", "", "for Github owner is required to build the registry url")
rootCmd.AddCommand(NPMPublishCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}