Commit bc03d2f2 authored by Christopher Harm's avatar Christopher Harm

Adding bash completion

Fixes #5
parent 7f193d46
Pipeline #31136 passed with stages
in 41 seconds
......@@ -30,9 +30,9 @@ var environmentSuffix string
var ciCmd = &cobra.Command{
Use: "ci",
Short: "Build tools for the CI system",
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("config called")
// },
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
}
func init() {
......
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion",
Short: "Generates bash completion scripts",
Long: `To load completion run
source <(devtool completion)
To configure your bash shell to load completions for each session add to your bashrc
# ~/.bashrc or ~/.profile
source <(devtool completion)
`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Do Nothing
},
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(os.Stdout)
},
}
func init() {
rootCmd.AddCommand(completionCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// completionCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// completionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
......@@ -22,9 +22,9 @@ import (
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage the projects build configuration",
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("config called")
// },
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
}
func init() {
......
......@@ -38,7 +38,12 @@ var rootCmd = &cobra.Command{
Long: `A tool used by software engineering to build applications.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PrintLogo()
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
......@@ -86,11 +91,11 @@ func initConfig() {
viper.SetEnvKeyReplacer(replacer)
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
} else {
color.Red(err.Error())
}
// if err := viper.ReadInConfig(); err == nil {
// fmt.Println("Using config file:", viper.ConfigFileUsed())
// } else {
// color.Red(err.Error())
// }
}
func PrintLogo() {
......
......@@ -3,6 +3,5 @@ package main
import "git.psu.edu/k8s/devtool/cmd"
func main() {
cmd.PrintLogo()
cmd.Execute()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment