Skip to content

Commit 84aba29

Browse files
committed
*: add disclaimer
1 parent fac3abc commit 84aba29

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

main.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
// protodoc generates Protocol Buffer documentation.
1616
//
1717
// Usage:
18-
// protodoc [flags]
18+
// protodoc [flags]
1919
//
2020
// Flags:
21-
// --directories value comma separated map of target directory to parse options (e.g. 'dirA=message,dirB=message_service')
22-
// -d, --directory string target directory where Protocol Buffer files are.
23-
// -h, --help help for protodoc
24-
// -l, --languages value language options in field descriptions (Go, C++, Java, Python, Ruby, C#) (default [])
25-
// --message-only-from-this-file string if specified, it parses only the messages in this file within the directory
26-
// -o, --output string output file path to save documentation
27-
// -p, --parse value Protocol Buffer types to parse (message, service) (default [service,message])
28-
// -t, --title string title of documentation
21+
// --directories=: comma separated map of target directory to parse options (e.g. 'dirA=message,dirB=message_service')
22+
// -d, --directory="": target directory where Protocol Buffer files are.
23+
// -c, --disclaimer="": disclaimer statement
24+
// -h, --help[=false]: help for protodoc
25+
// -l, --languages=[]: language options in field descriptions (Go, C++, Java, Python, Ruby, C#)
26+
// --message-only-from-this-file="": if specified, it parses only the messages in this file within the directory
27+
// -o, --output="": output file path to save documentation
28+
// -p, --parse=[service,message]: Protocol Buffer types to parse (message, service)
29+
// -t, --title="": title of documentation
2930
//
3031
package main
3132

@@ -52,6 +53,7 @@ var (
5253
languageOptions []string
5354
title string
5455
outputPath string
56+
disclaimer string
5557

5658
targetDirectories = newDirectoryOptions()
5759
messageOnlyFromThisFile string
@@ -106,6 +108,7 @@ func init() {
106108
rootCommand.PersistentFlags().StringSliceVarP(&languageOptions, "languages", "l", []string{}, "language options in field descriptions (Go, C++, Java, Python, Ruby, C#)")
107109
rootCommand.PersistentFlags().StringVarP(&title, "title", "t", "", "title of documentation")
108110
rootCommand.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "output file path to save documentation")
111+
rootCommand.PersistentFlags().StringVarP(&disclaimer, "disclaimer", "c", "", "disclaimer statement")
109112

110113
rootCommand.PersistentFlags().Var(&targetDirectories, "directories", "comma separated map of target directory to parse options (e.g. 'dirA=message,dirB=message_service')")
111114
rootCommand.PersistentFlags().StringVar(&messageOnlyFromThisFile, "message-only-from-this-file", "", "if specified, it parses only the messages in this file within the directory")
@@ -129,7 +132,7 @@ func CommandFunc(cmd *cobra.Command, args []string) error {
129132
}
130133
}
131134
log.Println("converting to markdown", title)
132-
rs, err = proto.Markdown(title, opts, languageOptions...)
135+
rs, err = proto.Markdown(disclaimer, title, opts, languageOptions...)
133136
if err != nil {
134137
return err
135138
}
@@ -147,7 +150,7 @@ func CommandFunc(cmd *cobra.Command, args []string) error {
147150
if err != nil {
148151
return err
149152
}
150-
ms, err := proto.Markdown("", elem.options, languageOptions...)
153+
ms, err := proto.Markdown(disclaimer, "", elem.options, languageOptions...)
151154
if err != nil {
152155
return err
153156
}

parse/markdown.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ const (
2929

3030
// Markdown saves 'Proto' to markdown documentation.
3131
// lopts are a slice of language options (C++, Java, Python, Go, Ruby, C#).
32-
func (p *Proto) Markdown(title string, parseOpts []ParseOption, lopts ...string) (string, error) {
32+
func (p *Proto) Markdown(disclaimer, title string, parseOpts []ParseOption, lopts ...string) (string, error) {
3333
p.Sort()
3434

3535
buf := new(bytes.Buffer)
36+
if len(disclaimer) > 0 {
37+
buf.WriteString(fmt.Sprintf("%s\n\n\n", disclaimer))
38+
}
3639
if len(title) > 0 {
3740
buf.WriteString(fmt.Sprintf("### %s\n\n\n", title))
3841
}

parse/markdown_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestMarkdown(t *testing.T) {
2121
if err != nil {
2222
t.Fatal(err)
2323
}
24-
if txt, err := proto.Markdown("etcdserverpb", []ParseOption{ParseService, ParseMessage}, "Go", "Java", "Python", "C++"); err != nil {
24+
if txt, err := proto.Markdown("this is test...", "etcdserverpb", []ParseOption{ParseService, ParseMessage}, "Go", "Java", "Python", "C++"); err != nil {
2525
t.Fatal(err)
2626
} else {
2727
err = toFile(txt, "testdata/README.md")

parse/testdata/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
this is test...
2+
3+
14
### etcdserverpb
25

36

sample.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
this is test...
2+
3+
14
### etcdserverpb
25

36

0 commit comments

Comments
 (0)