Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto completion for parameters values && args #149

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/cmd/connect/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package connect

import (
"fmt"
"os"

"github.com/litmuschaos/litmusctl/pkg/apis/environment"
"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
"os"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/k8s"
Expand Down Expand Up @@ -283,4 +285,9 @@ func init() {
infraCmd.Flags().Bool("skip-ssl", false, "Set whether Chaos infra will skip ssl/tls check (can be used for self-signed certs, if cert is not provided in portal)")
infraCmd.Flags().Bool("ns-exists", false, "Set the --ns-exists=false if the namespace mentioned in the --namespace flag is not existed else set it to --ns-exists=true | Note: Always set the boolean flag as --ns-exists=Boolean")
infraCmd.Flags().Bool("sa-exists", false, "Set the --sa-exists=false if the service-account mentioned in the --service-account flag is not existed else set it to --sa-exists=true | Note: Always set the boolean flag as --sa-exists=Boolean\"\n")

infraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
infraCmd.RegisterFlagCompletionFunc("installation-mode", completion.InstallModeTypeFlagCompletion)
infraCmd.RegisterFlagCompletionFunc("platform-name", completion.PlatformNameFlagCompletion)
infraCmd.RegisterFlagCompletionFunc("chaos-infra-type", completion.ChaosInfraTypeFlagCompletion)
}
8 changes: 7 additions & 1 deletion pkg/cmd/create/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package create

import (
"fmt"
"os"

models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
"github.com/litmuschaos/litmusctl/pkg/completion"
"github.com/litmuschaos/litmusctl/pkg/ops"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
"os"
)

// environmentCmd represents the Chaos infra command
Expand Down Expand Up @@ -155,4 +157,8 @@ func init() {
environmentCmd.Flags().String("type", "NON_PROD", "Set the installation mode for the kind of Chaos infra | Supported=cluster/namespace")
environmentCmd.Flags().String("name", "", "Set the Chaos infra name")
environmentCmd.Flags().String("description", "---", "Set the Chaos infra description")

environmentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
environmentCmd.RegisterFlagCompletionFunc("type", completion.InstallModeTypeFlagCompletion)

}
10 changes: 8 additions & 2 deletions pkg/cmd/create/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ package create

import (
"fmt"
"os"
"strings"

models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"
"github.com/litmuschaos/litmusctl/pkg/utils"
"os"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -145,4 +147,8 @@ func init() {
experimentCmd.Flags().String("chaos-infra-id", "", "Set the chaos-infra-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra")
experimentCmd.Flags().StringP("file", "f", "", "The manifest file for the Chaos Experiment")
experimentCmd.Flags().StringP("description", "d", "", "The Description for the Chaos Experiment")

experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
experimentCmd.RegisterFlagCompletionFunc("chaos-infra-id", completion.ChaosInfraFlagCompletion)

}
8 changes: 6 additions & 2 deletions pkg/cmd/delete/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package delete

import (
"fmt"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"os"

"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/utils"

Expand All @@ -36,7 +38,7 @@ var experimentCmd = &cobra.Command{

Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
`,
Args: cobra.ExactArgs(1),
ValidArgsFunction: completion.ExperimentIDCompletion,
Run: func(cmd *cobra.Command, args []string) {

// Fetch user credentials
Expand Down Expand Up @@ -109,4 +111,6 @@ func init() {
DeleteCmd.AddCommand(experimentCmd)

experimentCmd.Flags().String("project-id", "", "Set the project-id to create Chaos Experiment for the particular project. To see the projects, apply litmusctl get projects")
experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)

}
14 changes: 10 additions & 4 deletions pkg/cmd/describe/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package describe

import (
"fmt"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"os"
"strings"

"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
Expand All @@ -29,9 +31,11 @@ import (

// experimentCmd represents the Chaos Experiment command
var experimentCmd = &cobra.Command{
Use: "chaos-experiment",
Short: "Describe a Chaos Experiment within the project",
Long: `Describe a Chaos Experiment within the project`,
Use: "chaos-experiment",
Short: "Describe a Chaos Experiment within the project",
Long: `Describe a Chaos Experiment within the project`,
ValidArgsFunction: completion.ExperimentIDCompletion,

Run: func(cmd *cobra.Command, args []string) {
credentials, err := utils.GetCredentials(cmd)
utils.PrintError(err)
Expand Down Expand Up @@ -96,4 +100,6 @@ func init() {
DescribeCmd.AddCommand(experimentCmd)

experimentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Experiments from the particular project. To see the projects, apply litmusctl get projects")
experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)

}
6 changes: 5 additions & 1 deletion pkg/cmd/disconnect/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package disconnect

import (
"fmt"
"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
"os"
"strings"

"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/utils"

Expand Down Expand Up @@ -114,4 +116,6 @@ func init() {
DisconnectCmd.AddCommand(infraCmd)

infraCmd.Flags().String("project-id", "", "Set the project-id to disconnect Chaos Infrastructure for the particular project. To see the projects, apply litmusctl get projects")
infraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)

}
8 changes: 7 additions & 1 deletion pkg/cmd/get/experimentruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package get

import (
"fmt"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"os"
"strconv"
"strings"
"text/tabwriter"
"time"

"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -120,4 +122,8 @@ func init() {
experimentRunsCmd.Flags().BoolP("all", "A", false, "Set to true to display all Chaos Experiments runs")

experimentRunsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml")

experimentRunsCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
experimentRunsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion)

}
9 changes: 8 additions & 1 deletion pkg/cmd/get/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ package get

import (
"fmt"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"os"
"strings"
"text/tabwriter"
"time"

"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/gorhill/cronexpr"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/utils"
Expand Down Expand Up @@ -121,4 +123,9 @@ func init() {
experimentsCmd.Flags().StringP("chaos-infra", "A", "", "Set the Chaos Infrastructure name to display all Chaos experiments targeted towards that particular Chaos Infrastructure.")

experimentsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml")

experimentsCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
experimentsCmd.RegisterFlagCompletionFunc("chaos-infra", completion.ChaosInfraFlagCompletion)
experimentsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion)

}
10 changes: 8 additions & 2 deletions pkg/cmd/get/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ package get

import (
"fmt"
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
"os"
"strings"
"text/tabwriter"

models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
"github.com/litmuschaos/litmusctl/pkg/completion"

"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -94,4 +96,8 @@ func init() {
InfraCmd.Flags().String("project-id", "", "Set the project-id. To retrieve projects. Apply `litmusctl get projects`")

InfraCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml")

InfraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
InfraCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion)

}
3 changes: 3 additions & 0 deletions pkg/cmd/get/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/completion"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -66,4 +67,6 @@ func init() {
GetCmd.AddCommand(projectsCmd)

projectsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml")
projectsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion)

}
9 changes: 7 additions & 2 deletions pkg/cmd/run/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ package run

import (
"fmt"
"os"
"strings"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
"os"
"strings"
)

// experimentCmd represents the project command
Expand Down Expand Up @@ -118,4 +120,7 @@ func init() {

experimentCmd.Flags().String("project-id", "", "Set the project-id to create Chaos Experiment for the particular project. To see the projects, apply litmusctl get projects")
experimentCmd.Flags().String("experiment-id", "", "Set the environment-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra")

experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
experimentCmd.RegisterFlagCompletionFunc("experiment-id", completion.ExperimentIDCompletion)
}
11 changes: 9 additions & 2 deletions pkg/cmd/save/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ package save

import (
"fmt"
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"os"
"strings"

models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
"github.com/litmuschaos/litmusctl/pkg/completion"

//"time"

//"github.com/gorhill/cronexpr"
Expand Down Expand Up @@ -146,4 +149,8 @@ func init() {
experimentCmd.Flags().String("chaos-infra-id", "", "Set the chaos-infra-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra")
experimentCmd.Flags().StringP("file", "f", "", "The manifest file for the Chaos Experiment")
experimentCmd.Flags().StringP("description", "d", "", "The Description for the Chaos Experiment")

experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)
experimentCmd.RegisterFlagCompletionFunc("chaos-infra-id", completion.ChaosInfraFlagCompletion)

}
4 changes: 4 additions & 0 deletions pkg/cmd/upgrade/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/litmuschaos/litmusctl/pkg/apis"
"github.com/litmuschaos/litmusctl/pkg/completion"
"github.com/litmuschaos/litmusctl/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -66,4 +67,7 @@ func init() {
agentCmd.Flags().String("project-id", "", "Enter the project ID")
agentCmd.Flags().String("kubeconfig", "", "Enter the kubeconfig path(default: $HOME/.kube/config))")
agentCmd.Flags().String("chaos-delegate-id", "", "Enter the Chaos Delegate ID")

agentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion)

}
Loading
Loading