Exemple #1
0
func main() {
	var shouldCompact, showUsage, writeFile bool
	flag.BoolVar(&shouldCompact, "c", false, "Compact files instead of prettifying.")
	flag.BoolVar(&showUsage, "h", false, "Print a usage message.")
	flag.BoolVar(&writeFile, "w", false, "Write result to source file instead of stdout.")
	flag.Parse()

	if showUsage {
		usage()
		os.Exit(0)
	}

	action := jfmt.Pretty
	if shouldCompact {
		action = jfmt.Compact
	}

	var errCount int
	for _, fileName := range flag.Args() {
		err := act(action, fileName, writeFile)
		if err != nil {
			errCount++
		}
	}

	if errCount > 0 {
		lib.Errx(lib.ExitFailure, "Not all files succeeded.")
	}
}
Exemple #2
0
func main() {
	flag.Parse()
	if flag.NArg() != 1 {
		lib.Errx(lib.ExitFailure, "a single filename is required")
	}

	in, err := ioutil.ReadFile(flag.Arg(0))
	if err != nil {
		lib.Err(lib.ExitFailure, err, "couldn't read file")
	}

	p, _ := pem.Decode(in)
	if p == nil {
		lib.Errx(lib.ExitFailure, "%s isn't a PEM-encoded file", flag.Arg(0))
	}
	fmt.Printf("%s", p.Bytes)
}
Exemple #3
0
func main() {
	var shouldCompact bool
	flag.BoolVar(&shouldCompact, "c", false, "Compact files instead of prettifying.")
	flag.Parse()

	action := prettify
	if shouldCompact {
		action = compact
	}

	var errCount int
	for _, fileName := range flag.Args() {
		err := action(fileName)
		if err != nil {
			errCount++
		}
	}

	if errCount > 0 {
		lib.Errx(lib.ExitFailure, "Not all files succeeded.")
	}
}