forked from tsuru/tsuru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
48 lines (41 loc) · 1 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/tsuru/config"
"github.com/tsuru/tsuru/cmd"
"launchpad.net/gnuflag"
)
type configFile struct {
value string
}
func (v *configFile) String() string {
return v.value
}
func (v *configFile) Set(value string) error {
err := config.ReadConfigFile(value)
if err != nil {
return err
}
v.value = value
configPath = value
return nil
}
type tsrCommand struct {
cmd.Command
fs *gnuflag.FlagSet
file configFile
}
func (c *tsrCommand) Flags() *gnuflag.FlagSet {
if c.fs == nil {
if f, ok := c.Command.(cmd.FlaggedCommand); ok {
c.fs = f.Flags()
} else {
c.fs = gnuflag.NewFlagSet("tsr", gnuflag.ExitOnError)
}
c.fs.Var(&c.file, "config", "Path to configuration file (default to /etc/tsuru/tsuru.conf)")
c.fs.Var(&c.file, "c", "Path to configuration file (default to /etc/tsuru/tsuru.conf)")
}
return c.fs
}