CLI: Fix config flag being ignored

Passing --config had no effect when passed.  It will now be applied as
the last config file and before any env var overrrides.
This commit is contained in:
Jason Wilder
2015-02-15 14:57:49 -07:00
parent 9223c95481
commit b6428b08d0
8 changed files with 31 additions and 38 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"os"
"text/tabwriter"
@@ -34,9 +33,7 @@ var DeleteAccount = cli.Command{
}
func listAccounts(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
accountsQuery := m.GetAccountsQuery{}
if err := bus.Dispatch(&accountsQuery); err != nil {
@@ -53,9 +50,7 @@ func listAccounts(c *cli.Context) {
}
func createAccount(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required")
@@ -80,9 +75,7 @@ func createAccount(c *cli.Context) {
}
func deleteAccount(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required")

13
pkg/cmd/common.go Normal file
View File

@@ -0,0 +1,13 @@
package cmd
import (
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
)
func initRuntime(c *cli.Context) {
setting.NewConfigContext(c.GlobalString("config"))
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
}

View File

@@ -10,8 +10,6 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
)
var ImportDashboard = cli.Command{
@@ -48,9 +46,7 @@ func runImport(c *cli.Context) {
accountName := c.Args().First()
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
accountQuery := m.GetAccountByNameQuery{Name: accountName}
if err := bus.Dispatch(&accountQuery); err != nil {

View File

@@ -6,8 +6,6 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"os"
"text/tabwriter"
)
@@ -69,9 +67,7 @@ var (
)
func createDataSource(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if len(c.Args()) != 3 {
log.ConsoleFatal("Missing required arguments")
@@ -131,9 +127,7 @@ func createDataSource(c *cli.Context) {
}
func listDatasources(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required")
@@ -163,9 +157,7 @@ func listDatasources(c *cli.Context) {
}
func describeDataSource(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if len(c.Args()) != 2 {
log.ConsoleFatal("Account and datasource name args are required")
@@ -206,9 +198,7 @@ func describeDataSource(c *cli.Context) {
}
func deleteDataSource(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
initRuntime(c)
if len(c.Args()) != 2 {
log.ConsoleFatal("Account and datasource name args are required")

View File

@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
)
@@ -71,10 +70,9 @@ func runWeb(c *cli.Context) {
log.Info("Starting Grafana")
log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
setting.NewConfigContext()
initRuntime(c)
social.NewOAuthService()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
eventpublisher.Init()
var err error