Beispiel #1
0
func TestExecuteAsCommand(t *testing.T) {
	var err error

	// When using dumb TERM, messages should not be colorized.
	os.Setenv(EnvTerm, "dumb")
	err = fint.ExecuteAsCommand(&common.Opt{SrcRoot: SrcRootObjcNormal, ConfigPath: ConfigDefault, Locale: LocaleDefault, Id: LintIdObjc})
	testExpectError(t, err)

	// When using other than dumb TERM, messages should be colorized.
	os.Setenv(EnvTerm, "xterm-256color")
	err = fint.ExecuteAsCommand(&common.Opt{SrcRoot: SrcRootObjcNormal, ConfigPath: ConfigDefault, Locale: LocaleDefault, Id: LintIdObjc})
	testExpectError(t, err)

	// When there is only one violation, result message form should be singular.
	err = fint.ExecuteAsCommand(&common.Opt{SrcRoot: SrcRootObjcSingleError, ConfigPath: ConfigDefault, Locale: LocaleDefault, Id: LintIdObjc})
	testExpectError(t, err)

	// When SrcRoot is empty, lint should not be executed.
	err = fint.ExecuteAsCommand(&common.Opt{SrcRoot: "", ConfigPath: ConfigDefault, Locale: LocaleDefault, Id: LintIdObjc})
	testExpectErrorWithMessage(t, err, "fint: source directory is required.")
}
Beispiel #2
0
func main() {
	// Parse command
	if len(os.Args) == 1 {
		common.PrintUsage()
		os.Exit(ExitCodeError)
	}
	switch os.Args[1] {
	case "run":
	case "version":
		common.PrintVersion()
		os.Exit(ExitCodeSuccess)
	case "help":
		fallthrough
	default:
		common.PrintUsage()
		os.Exit(ExitCodeError)
	}

	// Parse flags
	var (
		srcRoot    = flag.String("s", "", "Source directory to be checked. Required.")
		configPath = flag.String("c", ".fint", "Config files directory. Default value is `.fint`.")
		locale     = flag.String("l", "en", "Message locale. Default value is `en`(English). Currently, `en` and `ja` is supported.")
		id         = flag.String("i", "", "ID of the target rule sets. Required.")
		html       = flag.String("h", "", "HTML report directory. Optional.")
		force      = flag.Bool("f", false, "Force generating report to existing directory. Default is `false`.")
		quiet      = flag.Bool("q", false, "Quiet mode. Suppresses output. Default is `false`.")
		template   = flag.String("template", "default", "HTML report template name. Default is `default`.")
		fix        = flag.Bool("fix", false, "Fix violations. Default is `false`.")
	)
	// Parse without filename and command
	flag.CommandLine.Parse(os.Args[2:])

	err := fint.ExecuteAsCommand(
		&common.Opt{
			SrcRoot:    *srcRoot,
			ConfigPath: *configPath,
			Locale:     *locale,
			Id:         *id,
			Html:       *html,
			Force:      *force,
			Quiet:      *quiet,
			Template:   *template,
			Fix:        *fix})
	if err != nil {
		os.Exit(ExitCodeError)
	}
}