コード例 #1
0
ファイル: flags_test.go プロジェクト: gitter-badger/st
func TestFlagErrors(t *testing.T) {
	Convey("Flag error testing", t, func() {

		Convey("We can return an error when no path is given", func() {
			SetArgs([]string{})
			err := ParseFlags()
			So(err, ShouldNotBeNil)
			So(err, ShouldEqual, sterrors.ErrNoPathsGiven)
		})

		Convey("Given a set of mismatched case flags", func() {
			Convey("A mutually exclusive parameters error is given", func() {
				SetArgs([]string{"-c", "-s", ""})
				err := ParseFlags()
				So(err, ShouldNotBeNil)
				So(err.Error(), ShouldEqual, sterrors.ErrMutuallyExclusiveParameters("c", "s").Error())
			})
		})

		Convey("Given a set of mismatched append mode flags", func() {
			Convey("A mutually exclusive parameters error is given", func() {
				SetArgs([]string{"-a", "-o", ""})
				err := ParseFlags()
				So(err, ShouldNotBeNil)
				So(err.Error(), ShouldEqual, sterrors.ErrMutuallyExclusiveParameters("o", "a").Error())
			})
		})

	})
}
コード例 #2
0
ファイル: flags.go プロジェクト: alistanis/st
func verify() error {

	// If GoFile is set, we know that we're being run by go generate, so we append the file name as our last argument
	// and we cheat so that we get the desired behavior
	if GoFile != "" {
		SetArgs(append(flag.Args(), GoFile))
		flag.Parse()
	}

	if flag.NArg() < 1 {
		return sterrors.ErrNoPathsGiven
	}

	if c && s {
		return sterrors.ErrMutuallyExclusiveParameters("c", "s")
	}

	if FlagOverwrite && FlagAppend {
		return sterrors.ErrMutuallyExclusiveParameters("o", "a")
	}

	if c {
		Case = Camel
	}

	if s {
		Case = Snake
	}

	if FlagOverwrite {
		AppendMode = Overwrite
	}

	if FlagAppend {
		AppendMode = Append
	}

	sterrors.Verbose = Verbose

	if IgnoredFieldsString != "" {
		IgnoredFields = strings.Split(IgnoredFieldsString, ",")
	}

	if IgnoredStructsString != "" {
		IgnoredStructs = strings.Split(IgnoredStructsString, ",")
	}
	return nil
}
コード例 #3
0
ファイル: flags.go プロジェクト: gitter-badger/st
func verify() error {

	if flag.NArg() < 1 {
		return sterrors.ErrNoPathsGiven
	}

	if c && s {
		return sterrors.ErrMutuallyExclusiveParameters("c", "s")
	}

	if Overwrite && Append {
		return sterrors.ErrMutuallyExclusiveParameters("o", "a")
	}

	if c {
		Case = Camel
	}

	if s {
		Case = Snake
	}

	if Overwrite {
		AppendMode = parse.Overwrite
	}

	if Append {
		AppendMode = parse.Append
	}

	sterrors.Verbose = Verbose

	if IgnoredFieldsString != "" {
		parse.IgnoredFields = strings.Split(IgnoredFieldsString, ",")
	}

	if IgnoredStructsString != "" {
		parse.IgnoredStructs = strings.Split(IgnoredStructsString, ",")
	}
	return nil
}