-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Executable binary | ||
drycop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* This is free and unencumbered software released into the public domain. */ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var configFile string | ||
var debug bool | ||
var verbose bool | ||
|
||
// RootCmd describes the `drycop` command | ||
var RootCmd = &cobra.Command{ | ||
Use: "drycop", | ||
Short: "DRYcop", | ||
Long: `DRYcop is a lint tool for DRY projects.`, | ||
Version: "0.0.0", | ||
} | ||
|
||
// Execute implements the `drycop` command | ||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "C", "", "Set config file (default: $HOME/.drycop/config.yaml)") | ||
RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable debugging") | ||
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Be verbose") | ||
RootCmd.SetVersionTemplate(`DRYcop {{printf "%s" .Version}} | ||
`) | ||
} | ||
|
||
// initConfig reads the configuration file and environment variables. | ||
func initConfig() { | ||
if configFile != "" { | ||
// Use the specified config file: | ||
viper.SetConfigFile(configFile) | ||
} else { | ||
// Search for config file in the current directory and under the home directory: | ||
viper.SetConfigName("config") | ||
viper.AddConfigPath(".") | ||
viper.AddConfigPath("$HOME/.drycop") | ||
} | ||
|
||
viper.AutomaticEnv() // read in environment variables that match | ||
|
||
// If a config file is found, read it in: | ||
if err := viper.ReadInConfig(); err == nil { | ||
if debug { | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* This is free and unencumbered software released into the public domain. */ | ||
|
||
// drycop is a lint tool for DRY projects. | ||
package main | ||
|
||
import "github.com/dryproject/drycop/drycop/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |