Skip to content

Commit

Permalink
refactor: move cobra/cmd/* to cobra/
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Jul 4, 2020
1 parent 3faaf7f commit 46fe8b4
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 102 deletions.
2 changes: 1 addition & 1 deletion cobra/cmd/add.go → cobra/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/add_test.go → cobra/add_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand Down
80 changes: 0 additions & 80 deletions cobra/cmd/root.go

This file was deleted.

2 changes: 1 addition & 1 deletion cobra/cmd/golden_test.go → cobra/golden_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/helpers.go → cobra/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/init.go → cobra/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/init_test.go → cobra/init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/license_agpl.go → cobra/license_agpl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

func initAgpl() {
Licenses["agpl"] = License{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initApache2() {
Licenses["apache"] = License{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initBsdClause2() {
Licenses["freebsd"] = License{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initBsdClause3() {
Licenses["bsd"] = License{
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/license_gpl_2.go → cobra/license_gpl_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initGpl2() {
Licenses["gpl2"] = License{
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/license_gpl_3.go → cobra/license_gpl_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initGpl3() {
Licenses["gpl3"] = License{
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/license_lgpl.go → cobra/license_lgpl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

func initLgpl() {
Licenses["lgpl"] = License{
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/license_mit.go → cobra/license_mit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

func initMit() {
Licenses["mit"] = License{
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/licenses.go → cobra/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Parts inspired by https://github.com/ryanuber/go-license

package cmd
package main

import (
"fmt"
Expand Down
59 changes: 56 additions & 3 deletions cobra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,66 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra/cobra/cmd"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func main() {
if err := cmd.Execute(); err != nil {
os.Exit(1)
er(rootCmd.Execute())
}

var (
// Used for flags.
cfgFile string
userLicense string

rootCmd = &cobra.Command{
Use: "cobra",
Short: "A generator for Cobra based Applications",
Long: `Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
}
)

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
er(viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author")))
er(viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper")))
viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
viper.SetDefault("license", "apache")

rootCmd.AddCommand(addCmd)
rootCmd.AddCommand(initCmd)
}

func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
if err != nil {
er(err)
}

// Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".cobra")
}

viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
2 changes: 1 addition & 1 deletion cobra/cmd/project.go → cobra/project.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cobra/cmd/project_test.go → cobra/project_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cmd
package main

/* todo: write tests */
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cobra"
"github.com/umarcor/cobra"
)

// testCmd represents the test command
Expand Down
2 changes: 1 addition & 1 deletion cobra/tpl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/umarcor/cobra"
)
// {{ .CmdName }}Cmd represents the {{ .CmdName }} command
Expand Down

0 comments on commit 46fe8b4

Please sign in to comment.