Skip to content

Commit

Permalink
Merge 542d0ed into f1b85bf
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Jan 17, 2019
2 parents f1b85bf + 542d0ed commit 8fc346c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 53 deletions.
20 changes: 1 addition & 19 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,9 @@ import (
mkr "github.com/mackerelio/mackerel-client-go"
"github.com/mackerelio/mkr/logger"
"github.com/mackerelio/mkr/plugin"
"gopkg.in/urfave/cli.v1"
cli "gopkg.in/urfave/cli.v1"
)

func init() {
// Requirements:
// - .Description: First and last line is blank.
// - .ArgsUsage: ArgsUsage includes flag usages (e.g. [-v|verbose] <hostId>).
// All cli.Command should have ArgsUsage field.
cli.CommandHelpTemplate = `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Description}}
DESCRIPTION:{{.Description}}{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
}

// Commands cli.Command object list
var Commands = []cli.Command{
commandStatus,
Expand Down
9 changes: 1 addition & 8 deletions commands_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

import (
"strings"
"testing"

"gopkg.in/urfave/cli.v1"
cli "gopkg.in/urfave/cli.v1"
)

func TestCommands_requirements(t *testing.T) {
Expand All @@ -20,12 +19,6 @@ func TestCommands_requirements(t *testing.T) {
}
}
for _, c := range cs {
if !strings.HasPrefix(c.Description, "\n ") {
t.Errorf("%s: cli.Command.Description should start with '\\n ', got:\n%s", c.Name, c.Description)
}
if !strings.HasSuffix(c.Description, "\n") {
t.Errorf("%s: cli.Command.Description should end with '\\n', got:\n%s", c.Name, c.Description)
}
if len(c.Flags) > 0 && c.ArgsUsage == "" {
t.Errorf("%s: cli.Command.ArgsUsage should not be empty. Describe flag options.", c.Name)
}
Expand Down
18 changes: 1 addition & 17 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/mackerelio/mackerel-agent/config"
)

const idFileName = "id"

func idFilePath(root string) string {
return filepath.Join(root, idFileName)
}

func loadHostID(root string) (string, error) {
content, err := ioutil.ReadFile(idFilePath(root))
if err != nil {
return "", err
}
return string(content), nil
}

// LoadApibaseFromConfig gets mackerel api Base URL (usually https://api.mackerelio.com/) from mackerel-agent.conf if it's installed mackerel-agent on localhost
func LoadApibaseFromConfig(conffile string) string {
conf, err := config.LoadConfig(conffile)
Expand Down Expand Up @@ -65,7 +49,7 @@ func LoadHostIDFromConfig(conffile string) string {
if err != nil {
return ""
}
hostID, err := loadHostID(conf.Root)
hostID, err := conf.LoadHostID()
if err != nil {
return ""
}
Expand Down
9 changes: 5 additions & 4 deletions dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"strconv"
"strings"

"github.com/mackerelio/mackerel-client-go"
mackerel "github.com/mackerelio/mackerel-client-go"
"github.com/mackerelio/mkr/logger"
"gopkg.in/urfave/cli.v1"
"gopkg.in/yaml.v2"
cli "gopkg.in/urfave/cli.v1"
yaml "gopkg.in/yaml.v2"
)

var commandDashboards = cli.Command{
Name: "dashboards",
Name: "dashboards",
Usage: "Generating custom dashboards",
Description: `
Generating dashboards. See https://mackerel.io/docs/entry/advanced/cli
`,
Expand Down
6 changes: 1 addition & 5 deletions mkr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package main
import (
"fmt"
"os"
"runtime"

"github.com/mackerelio/mackerel-agent/config"
"github.com/mackerelio/mkr/logger"
"gopkg.in/urfave/cli.v1"
cli "gopkg.in/urfave/cli.v1"
)

func main() {
Expand All @@ -30,9 +29,6 @@ func main() {
},
}

cpu := runtime.NumCPU()
runtime.GOMAXPROCS(cpu)

err := app.Run(os.Args)
if err != nil {
logger.Log("error", err.Error())
Expand Down

0 comments on commit 8fc346c

Please sign in to comment.