Skip to content

Commit

Permalink
add version option
Browse files Browse the repository at this point in the history
* Update CLI tools to utilize cobra
* Reworked configuration loading to support full-path to config file
* Add version option
  • Loading branch information
dhollinger committed Oct 8, 2022
1 parent c03c8fa commit 3f83c2a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
21 changes: 12 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ type Config struct {
} `mapstructure:"r10k"`
}

func Init(path string) {
func Init(path *string) {
var err error

v := viper.New()
v.SetConfigType("yml")
v.SetConfigName("webhook")
v.AddConfigPath(path)
v.AddConfigPath(".")
v.AddConfigPath("/etc/voxpupuli/webhook/")
v.AddConfigPath("../config/")
v.AddConfigPath("config/")

if path != nil {
v.SetConfigFile(*path)
} else {
v.SetConfigType("yml")
v.SetConfigName("webhook")
v.AddConfigPath(".")
v.AddConfigPath("/etc/voxpupuli/webhook/")
v.AddConfigPath("../config/")
v.AddConfigPath("config/")
}
err = v.ReadInConfig()
if err != nil {
log.Fatalf("error on parsing config file: %v", err)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/proclaim/mock-slack v0.0.0-20201019114328-0aae156a5005
github.com/sirupsen/logrus v1.8.1
github.com/slack-go/slack v0.9.5
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
github.com/xanzy/go-gitlab v0.50.1
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -194,6 +195,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -253,6 +256,7 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand All @@ -268,6 +272,8 @@ github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/r10k-config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

func Test_GetR10kConfig(t *testing.T) {
h := Helper{}
config.Init("./yaml")
mCfg := "./yaml/webhook.yaml"
config.Init(&mCfg)

conf := h.GetR10kConfig()
assert.Equal(t, ConfigFile, conf)
Expand Down
29 changes: 14 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/voxpupuli/webhook-go/config"
"github.com/voxpupuli/webhook-go/server"
"github.com/voxpupuli/webhook-go/cmd"
)

// Main function that starts the application
// // Main function that starts the application
// func main() {
// flag.Usage = func() {
// fmt.Println("Usage: server -c {path}")
// os.Exit(1)
// }
// confPath := flag.String("c", ".", "")
// flag.Parse()
// config.Init(*confPath)
// server.Init()
// }

func main() {
flag.Usage = func() {
fmt.Println("Usage: server -c {path}")
os.Exit(1)
}
confPath := flag.String("c", ".", "")
flag.Parse()
config.Init(*confPath)
server.Init()
cmd.Execute()
}

0 comments on commit 3f83c2a

Please sign in to comment.