Merge "RIC:1060: Change in PTL"
[ric-plt/sdlgo.git] / internal / cli / completion.go
1 /*
2    Copyright (c) 2022 Nokia.
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20  */
21
22 package cli
23
24 import (
25         "io"
26         "os"
27
28         "github.com/spf13/cobra"
29 )
30
31 func init() {
32         rootCmd.AddCommand(newCompletionCmd(os.Stdout))
33 }
34
35 var completionLong = `# To load bash completions:
36 source <(sdlcli completion bash)
37
38 # To load completions for each session, execute once:
39 sdlcli completion bash > /usr/share/bash-completion/completions/sdlcli
40 `
41
42 func newCompletionCmd(out io.Writer) *cobra.Command {
43         cmd := &cobra.Command{
44                 Use:                   "completion [bash]",
45                 Short:                 "Generate shell completion script",
46                 Long:                  completionLong,
47                 DisableFlagsInUseLine: true,
48                 ValidArgs:             []string{"bash"},
49                 Args:                  cobra.ExactValidArgs(1),
50                 Run: func(cmd *cobra.Command, args []string) {
51                         switch args[0] {
52                         case "bash":
53                                 cmd.Root().GenBashCompletion(out)
54                         }
55                 },
56         }
57         return cmd
58 }