refactor: fix ci and put files where they belong (#15)

License: MIT
Signed-off-by: Henrique Dias <[email protected]>
This commit is contained in:
Henrique Dias
2019-05-12 19:40:58 +01:00
committed by GitHub
parent e81638120b
commit c5f3907994
17 changed files with 129 additions and 187 deletions
+4 -6
View File
@@ -1,14 +1,12 @@
package main
package cmd
import (
"log"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
// Execute executes the commands.
func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
package main
package cmd
import (
"errors"
@@ -7,7 +7,7 @@ import (
"regexp"
"strings"
"github.com/hacdias/webdav"
"github.com/hacdias/webdav/webdav"
"github.com/spf13/pflag"
v "github.com/spf13/viper"
wd "golang.org/x/net/webdav"
+26 -5
View File
@@ -1,4 +1,4 @@
package main
package cmd
import (
"fmt"
@@ -20,7 +20,6 @@ func init() {
flags := rootCmd.Flags()
flags.StringVarP(&cfgFile, "config", "c", "", "config file path")
flags.Bool("auth", true, "whether to use authentication or not")
flags.BoolP("tls", "t", false, "enable tls")
flags.String("cert", "cert.pem", "TLS certificate")
flags.String("key", "key.pem", "TLS key")
@@ -30,7 +29,23 @@ func init() {
var rootCmd = &cobra.Command{
Use: "webdav",
Short: "A simple to use Web Dav server",
Short: "A simple to use WebDAV server",
Long: `If you don't set "config", it will look for a configuration file called
config.{json, toml, yaml, yml} in the following directories:
- ./
- /etc/webdav/
The precedence of the configuration values are as follows:
- flags
- environment variables
- configuration file
- defaults
The environment variables are prefixed by "WD_" followed by the option
name in caps. So to set "cert" via an env variable, you should
set WD_CERT.`,
Run: func(cmd *cobra.Command, args []string) {
flags := cmd.Flags()
@@ -72,6 +87,12 @@ func initConfig() {
v.AutomaticEnv()
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
err := v.ReadInConfig()
checkErr(err)
if err := v.ReadInConfig(); err != nil {
if _, ok := err.(v.ConfigParseError); ok {
panic(err)
}
cfgFile = "No config file used"
} else {
cfgFile = "Using config file: " + v.ConfigFileUsed()
}
}
+19
View File
@@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var version = "(untracked)"
func init() {
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("WebDAV version " + version)
},
})
}
+1 -1
View File
@@ -1,4 +1,4 @@
package main
package cmd
import (
"log"