-
Notifications
You must be signed in to change notification settings - Fork 2
/
push.go
110 lines (85 loc) 路 2.39 KB
/
push.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cmd
import (
"log"
util "github.com/docat-org/docatl/internal"
docatl "github.com/docat-org/docatl/pkg"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var pushCmd = &cobra.Command{
Use: "push DOCS [PROJECT [VERSION]]",
Short: "Push documentation to a docat server",
Long: `Push documentation to a docat server.
Upload documentation:
docatl push ./docs.zip myproject 1.0.0 -t latest
Build & Upload documentation:
docatl push ./docs/ myproject 1.0.0 -t latest
Upload documentation to specific docat server:
docatl push --host https://localhost:8000 ./docs.zip myproject 1.0.0 -t latest
`,
Args: cobra.RangeArgs(1, 3),
Run: func(cmd *cobra.Command, args []string) {
docsPath := util.ResolvePath(args[0])
project := viper.GetString("project")
version := viper.GetString("version")
unpackArgs := func() (string, string) {
if project == "" {
if len(args) < 2 {
log.Fatalf("when PROJECT is not given, the DOCATL_PROJECT variable must contain it")
}
project = args[1]
}
if version == "" {
if len(args) < 3 {
log.Fatalf("when VERSION is not given, the DOCATL_VERSION variable must contain it")
} else {
version = args[2]
}
}
return project, version
}
if util.IsDirectory(docsPath) {
project, version = unpackArgs()
docsPathBuilt, err := docatl.Build(docsPath, docatl.BuildMetadata{
Host: docat.Host,
Project: project,
Version: version,
})
if err != nil {
log.Fatal(err)
}
docsPath = docsPathBuilt
} else {
meta, err := docatl.ExtractMetadata(docsPath)
if err != nil {
log.Fatal(err)
}
if meta.Host != "" {
docat.Host = meta.Host
}
project = meta.Project
version = meta.Version
project, version = unpackArgs()
}
ensureHost()
err := docat.Post(project, version, docsPath)
if err != nil {
log.Fatal(err)
}
log.Printf("Successfully pushed documentation version %s to project %s", version, project)
tags, err := cmd.Flags().GetStringSlice("tag")
cobra.CheckErr(err)
for _, tag := range tags {
err = docat.Tag(project, version, tag)
if err != nil {
log.Fatal(err)
}
log.Printf("Successfully tagged version %s of project %s as %s", version, project, tag)
}
},
}
func init() {
rootCmd.AddCommand(pushCmd)
pushCmd.PersistentFlags().StringSliceP("tag", "t", []string{}, "Additional Tag for this version (repeatable)")
setupEnv(pushCmd)
}