File tree 2 files changed +62
-0
lines changed 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2020 The Gitea Authors. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package cmd
6
+
7
+ import (
8
+ "fmt"
9
+ "os"
10
+ "strings"
11
+
12
+ "github.com/urfave/cli"
13
+ )
14
+
15
+ // CmdDocs represents the available docs sub-command.
16
+ var CmdDocs = cli.Command {
17
+ Name : "docs" ,
18
+ Usage : "Output CLI documentation" ,
19
+ Description : "A command to output Gitea's CLI documentation, optionally to a file." ,
20
+ Action : runDocs ,
21
+ Flags : []cli.Flag {
22
+ & cli.BoolFlag {
23
+ Name : "man" ,
24
+ Usage : "Output man pages instead" ,
25
+ },
26
+ & cli.StringFlag {
27
+ Name : "output, o" ,
28
+ Usage : "Path to output to instead of stdout (will overwrite if exists)" ,
29
+ },
30
+ },
31
+ }
32
+
33
+ func runDocs (ctx * cli.Context ) error {
34
+ docs , err := ctx .App .ToMarkdown ()
35
+ if ctx .Bool ("man" ) {
36
+ docs , err = ctx .App .ToMan ()
37
+ }
38
+ if err != nil {
39
+ return err
40
+ }
41
+
42
+ if ! ctx .Bool ("man" ) {
43
+ // Clean up markdown. The following bug was fixed in v2, but is present in v1.
44
+ // It affects markdown output (even though the issue is referring to man pages)
45
+ // https://github.com/urfave/cli/issues/1040
46
+ docs = docs [strings .Index (docs , "#" ):]
47
+ }
48
+
49
+ out := os .Stdout
50
+ if ctx .String ("output" ) != "" {
51
+ fi , err := os .Create (ctx .String ("output" ))
52
+ if err != nil {
53
+ return err
54
+ }
55
+ defer fi .Close ()
56
+ out = fi
57
+ }
58
+
59
+ _ , err = fmt .Fprintln (out , docs )
60
+ return err
61
+ }
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ arguments - which can alternatively be run by running the subcommand web.`
69
69
cmd .CmdManager ,
70
70
cmd .Cmdembedded ,
71
71
cmd .CmdMigrateStorage ,
72
+ cmd .CmdDocs ,
72
73
}
73
74
// Now adjust these commands to add our global configuration options
74
75
You can’t perform that action at this time.
0 commit comments