Fixed logger interface to be compatible with wider range of loggers.

This commit is contained in:
Stanislav N. aka pztrn 2018-04-27 13:13:23 +05:00
parent 6543841fc3
commit 79495d352c
3 changed files with 11 additions and 11 deletions

View File

@ -51,7 +51,7 @@ type Flagger struct {
func (f *Flagger) AddFlag(flag *Flag) error {
_, present := f.flags[flag.Name]
if present {
logger.Fatalln("Cannot add flag '" + flag.Name + "' - already added!")
logger.Fatal("Cannot add flag '" + flag.Name + "' - already added!")
return errors.New("Cannot add flag '" + flag.Name + "' - already added!")
}
@ -92,7 +92,7 @@ func (f *Flagger) GetStringValue(name string) (string, error) {
// Flagger initialization.
func (f *Flagger) Initialize() {
logger.Println("Initializing CLI parameters parser...")
logger.Print("Initializing CLI parameters parser...")
f.flags = make(map[string]*Flag)
@ -121,6 +121,6 @@ func (f *Flagger) Parse() {
}
}
logger.Println("Parsing CLI parameters...")
logger.Print("Parsing CLI parameters...")
flag.Parse()
}

View File

@ -44,13 +44,13 @@ func TestFlaggerInitialization(t *testing.T) {
}
func TestFlaggerAddBoolFlag(t *testing.T) {
flag_testbool := Flag{
flagTestBool := Flag{
Name: "testboolflag",
Description: "Testing boolean flag",
Type: "bool",
DefaultValue: true,
}
err := f.AddFlag(&flag_testbool)
err := f.AddFlag(&flagTestBool)
if err != nil {
t.Fatal("Failed to add boolean flag!")
t.FailNow()
@ -58,13 +58,13 @@ func TestFlaggerAddBoolFlag(t *testing.T) {
}
func TestFlaggerAddIntFlag(t *testing.T) {
flag_testint := Flag{
flagTestInt := Flag{
Name: "testintflag",
Description: "Testing integer flag",
Type: "int",
DefaultValue: 1,
}
err := f.AddFlag(&flag_testint)
err := f.AddFlag(&flagTestInt)
if err != nil {
t.Fatal("Failed to add integer flag!")
t.FailNow()
@ -72,13 +72,13 @@ func TestFlaggerAddIntFlag(t *testing.T) {
}
func TestFlaggerAddStringFlag(t *testing.T) {
flag_teststring := Flag{
flagTestString := Flag{
Name: "teststringflag",
Description: "Testing string flag",
Type: "string",
DefaultValue: "superstring",
}
err := f.AddFlag(&flag_teststring)
err := f.AddFlag(&flagTestString)
if err != nil {
t.Fatal("Failed to add string flag!")
t.FailNow()

View File

@ -26,6 +26,6 @@ package flagger
// LoggerInterface provide logging interface, so everyone can inject own
// logging handlers.
type LoggerInterface interface {
Fatalln(args ...interface{})
Println(v ...interface{})
Fatal(v ...interface{})
Print(v ...interface{})
}