FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
updatecli/cmd/docs.go at main · updatecli/updatecli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
updatecli
/
updatecli
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
147
Star
961
Code
Issues
106
Pull requests
18
Discussions
Actions
Projects
Security and quality
3
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
updatecli
/
cmd
/
docs.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
126 lines (100 loc) · 2.76 KB
Breadcrumbs
updatecli
/
cmd
/
docs.go
Copy path
File metadata and controls
126 lines (100 loc) · 2.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package
cmd
import
(
"crypto/sha256"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
// The docs command is a hidden sub-command that generates the documentation for www.updatecli.io
var
(
docPrepender
=
func
(
s
string
)
string
{
header
:=
"---
\n
"
name
:=
filepath
.
Base
(
s
)
name
=
strings
.
ReplaceAll
(
name
,
"_"
,
" "
)
name
=
strings
.
TrimSuffix
(
name
,
".md"
)
header
=
header
+
fmt
.
Sprintf
(
"title: %v
\n
"
,
name
)
header
=
header
+
fmt
.
Sprintf
(
"description: Documentation for the command `%v`
\n
"
,
name
)
header
=
header
+
fmt
.
Sprintf
(
"lead: Documentation for the command `%v`
\n
"
,
name
)
header
=
header
+
"draft: false
\n
"
header
=
header
+
"images: []
\n
"
header
=
header
+
"menu:
\n
docs:
\n
parent:
\"
commands
\"
\n
"
header
=
header
+
"weight: 130
\n
"
header
=
header
+
"toc: true
\n
"
header
=
header
+
"---
\n
\n
"
return
header
}
linkhandler
=
func
(
s
string
)
string
{
s
=
strings
.
ToLower
(
s
)
s
=
strings
.
TrimSuffix
(
s
,
".md"
)
s
=
"/docs/commands/"
+
s
return
s
}
docsDir
string
docsCmd
=
&
cobra.
Command
{
Use
:
"docs"
,
Hidden
:
true
,
Short
:
"Generate updatecli documentation"
,
RunE
:
func
(
cmd
*
cobra.
Command
,
args
[]
string
)
error
{
rootCmd
.
DisableAutoGenTag
=
true
before
,
err
:=
snapshotDir
(
docsDir
)
if
err
!=
nil
{
return
err
}
if
err
=
doc
.
GenMarkdownTreeCustom
(
rootCmd
,
docsDir
,
docPrepender
,
linkhandler
);
err
!=
nil
{
return
err
}
after
,
err
:=
snapshotDir
(
docsDir
)
if
err
!=
nil
{
return
err
}
for
path
,
hash
:=
range
after
{
if
prev
,
exists
:=
before
[
path
];
!
exists
||
prev
!=
hash
{
logrus
.
Infof
(
"Documentation files updated in %q"
,
docsDir
)
os
.
Exit
(
2
)
}
}
logrus
.
Infof
(
"Documentation files already up to date in %q"
,
docsDir
)
return
nil
},
}
)
func
init
() {
docsCmd
.
Flags
().
StringVarP
(
&
docsDir
,
"docs"
,
"d"
,
"./docs"
,
"Specify the directory where to generate documentation files"
)
}
// snapshotDir returns a map of file paths (relative to dir) to their SHA-256 hash.
// If the directory does not exist yet, an empty map is returned.
func
snapshotDir
(
dir
string
) (
map
[
string
][
sha256
.
Size
]
byte
,
error
) {
hashes
:=
make
(
map
[
string
][
sha256
.
Size
]
byte
)
if
_
,
err
:=
os
.
Stat
(
dir
);
os
.
IsNotExist
(
err
) {
return
hashes
,
nil
}
err
:=
filepath
.
WalkDir
(
dir
,
func
(
path
string
,
d
os.
DirEntry
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
if
d
.
IsDir
() {
return
nil
}
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
h
:=
sha256
.
New
()
if
_
,
err
=
io
.
Copy
(
h
,
f
);
err
!=
nil
{
return
err
}
rel
,
err
:=
filepath
.
Rel
(
dir
,
path
)
if
err
!=
nil
{
return
err
}
hashes
[
rel
]
=
[
sha256
.
Size
]
byte
(
h
.
Sum
(
nil
))
return
nil
})
return
hashes
,
err
}
Back
|
FazBrowse Home
|
New Git URL