2008-09-18 17:58:37 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-01-07 17:54:03 -07:00
|
|
|
import (
|
2009-02-06 16:26:30 -07:00
|
|
|
"os";
|
|
|
|
"flag";
|
2009-01-07 17:54:03 -07:00
|
|
|
Platform "platform";
|
|
|
|
Printer "printer";
|
|
|
|
Compilation "compilation";
|
|
|
|
)
|
2008-09-18 17:58:37 -06:00
|
|
|
|
|
|
|
|
|
|
|
var (
|
2008-10-24 15:04:54 -06:00
|
|
|
flags Compilation.Flags;
|
2009-02-06 16:26:30 -07:00
|
|
|
silent = flag.Bool("s", false, "silent mode: no pretty print output");
|
|
|
|
html = flag.Bool("html", false, "generate html");
|
2008-09-18 17:58:37 -06:00
|
|
|
)
|
|
|
|
|
2009-01-09 14:42:46 -07:00
|
|
|
func init() {
|
2009-02-06 16:26:30 -07:00
|
|
|
flag.BoolVar(&flags.Verbose, "v", false, "verbose mode: trace parsing");
|
|
|
|
flag.BoolVar(&flags.Deps, "d", false, "print dependency information only");
|
|
|
|
flag.BoolVar(&flags.Columns, "columns", Platform.USER == "gri", "print column info in error messages");
|
2009-01-09 14:42:46 -07:00
|
|
|
}
|
|
|
|
|
2008-09-18 17:58:37 -06:00
|
|
|
|
2009-01-15 18:16:41 -07:00
|
|
|
func usage() {
|
2008-09-19 13:12:28 -06:00
|
|
|
print("usage: pretty { flags } { files }\n");
|
2009-02-06 16:26:30 -07:00
|
|
|
flag.PrintDefaults();
|
2009-01-16 15:58:14 -07:00
|
|
|
sys.Exit(0);
|
2008-09-19 13:12:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-18 17:58:37 -06:00
|
|
|
func main() {
|
2009-02-06 16:26:30 -07:00
|
|
|
flag.Parse();
|
2009-01-16 15:58:14 -07:00
|
|
|
|
2009-02-06 16:26:30 -07:00
|
|
|
if flag.NFlag() == 0 && flag.NArg() == 0 {
|
2009-01-15 18:16:41 -07:00
|
|
|
usage();
|
2008-09-19 13:12:28 -06:00
|
|
|
}
|
|
|
|
|
2008-09-18 17:58:37 -06:00
|
|
|
// process files
|
2009-02-06 16:26:30 -07:00
|
|
|
for i := 0; i < flag.NArg(); i++ {
|
|
|
|
src_file := flag.Arg(i);
|
2008-09-18 17:58:37 -06:00
|
|
|
|
2009-02-06 12:10:25 -07:00
|
|
|
if flags.Deps {
|
2008-10-26 22:32:30 -06:00
|
|
|
Compilation.ComputeDeps(src_file, &flags);
|
2009-01-16 15:58:14 -07:00
|
|
|
|
2008-10-26 22:32:30 -06:00
|
|
|
} else {
|
|
|
|
prog, nerrors := Compilation.Compile(src_file, &flags);
|
|
|
|
if nerrors > 0 {
|
2009-01-30 16:31:04 -07:00
|
|
|
sys.Exit(1);
|
2008-10-26 22:32:30 -06:00
|
|
|
}
|
2009-03-02 21:27:09 -07:00
|
|
|
if !*silent {
|
2009-02-06 16:26:30 -07:00
|
|
|
Printer.Print(os.Stdout, *html, prog);
|
2008-10-26 22:32:30 -06:00
|
|
|
}
|
2008-09-23 17:40:12 -06:00
|
|
|
}
|
2008-09-18 17:58:37 -06:00
|
|
|
}
|
|
|
|
}
|