Skip to content

Commit ae83648

Browse files
authored
feat: Adds line to template for custom role annotation (#31)
1 parent abe0e2d commit ae83648

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cobra2snooty.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func GenDocs(cmd *cobra.Command, w io.Writer) error {
101101
}
102102
buf.WriteString("\n" + long + "\n")
103103
}
104+
105+
requiredRole(buf, cmd)
104106
buf.WriteString("\n")
105107

106108
if cmd.Runnable() {

requiredRole.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2022 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cobra2snooty
16+
17+
import (
18+
"bytes"
19+
20+
"github.com/spf13/cobra"
21+
)
22+
23+
func requiredRole(buf *bytes.Buffer, cmd *cobra.Command) {
24+
if cmd.Annotations["requiredRole"] != "" {
25+
buf.WriteString("\nTo use this command, the requesting user or API key must have the " + cmd.Annotations["requiredRole"] + " role.\n")
26+
}
27+
}

0 commit comments

Comments
 (0)