// NewApp generate a new application instance
NewApp generate a new application instance
// NewApp generate a new application instance
func NewApp() cli.App {
	var path string
	var checkOnly bool
	app := cli.NewApp()
	app.Name = "utfbom-remove"
	app.Version = "v1.0.2"
	app.Compiled = time.Now()
	app.Authors = []cli.Author{
		{
			Name:  "alastairruhm",
			Email: "alastairruhm@gmail.com",
		},
	}
	app.Copyright = "(c) 2017 alastairruhm"
	app.Usage = "detect and remove BOM in utf-8 encoding files"
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:        "check-only",
			Usage:       "dry-run mode",
			Destination: &checkOnly,
		},
		cli.StringFlag{
			Name:        "path",
			Value:       ".",
			Usage:       "the path to scan",
			Destination: &path,
		},
	}
	app.Action = func(c *cli.Context) error {
		if c.NArg() == 0 { 
			cli.ShowAppHelp(c)
		}
		absDir, err := filepath.Abs(path)
		if err != nil {
			fmt.Fprintf(c.App.Writer, "Error: %#v\n", err)
			return cli.NewExitError("error in path "+path, 1)
		}
		if checkOnly {
			files, err := ListFilesWithBOM(absDir)
			if err != nil {
				fmt.Println(err)
				return err
			}
			for _, file := range files {
				fmt.Fprintf(c.App.Writer, "%s\n", file)
			}
		}
		err = RemoveBomForFiles(path)
		if err != nil {
			return err
		}
		return nil
	}
	return *app
}
func NewApp ( ) cli . App { var path string var checkOnly bool app := cli . NewApp ( ) app . Name = " " app . Version = " " app . Compiled = time . Now ( ) app . Authors = [ ] cli . Author { { Name : " " , Email : " " , } , } app . Copyright = " " app . Usage = " " app . Flags = [ ] cli . Flag { cli . BoolFlag { Name : " " , Usage : " " , Destination : & checkOnly , } , cli . StringFlag { Name : " " , Value : " " , Usage : " " , Destination : & path , } , } app . Action = func ( c * cli . Context ) error { if c . NArg ( ) == 0 { cli . ShowAppHelp ( c ) } absDir , err := filepath . Abs ( path ) if err != nil { fmt . Fprintf ( c . App . Writer , " \n " , err ) return cli . NewExitError ( " " + path , 1 ) } if checkOnly { files , err := ListFilesWithBOM ( absDir ) if err != nil { fmt . Println ( err ) return err } for _ , file := range files { fmt . Fprintf ( c . App . Writer , " \n " , file ) } } err = RemoveBomForFiles ( path ) if err != nil { return err } return nil } return * app }
NewApp generate a new application instance
NewApp generate a new application instance
// show help info when no parameter given