Esempio n. 1
0
func runDiff(pathFrom, pathTo, pathBase string) {
	config, err := loadConfig()
	if err != nil {
		os.Stderr.WriteString("warning: error parsing .deltarc file")
	}
	d, err := diff(pathFrom, pathTo)
	if err != nil {
		os.Stderr.WriteString(err.Error())
		return
	}
	if err != nil {
		os.Stderr.WriteString(err.Error())
		return
	}
	if *format == FormatOptionDefault {
		switch *output {
		case OutputOptionBrowser, OutputOptionGist:
			*format = FormatOptionHTML
		case OutputOptionCLI:
			*format = FormatOptionText
		}
	}

	switch *format {
	case FormatOptionHTML:
		page, err := html(d, pathFrom, pathTo, pathBase, config)
		if err != nil {
			os.Stderr.WriteString(err.Error())
			return
		}
		switch *output {
		case OutputOptionCLI:
			page.WriteTo(os.Stdout)
		case OutputOptionGist:
			uploadGist(page.Bytes())
		case OutputOptionBrowser:
			browser.OpenReader(page)
		}

	case FormatOptionText:
		switch *output {
		case OutputOptionCLI:
			fmt.Println(formatter.ColoredText(d))
		case OutputOptionGist:
			uploadGist([]byte(formatter.Text(d)))
		case OutputOptionBrowser:
			browser.OpenReader(bytes.NewBufferString(formatter.Text(d)))
		}
	}
}
Esempio n. 2
0
func main() {
	for _, pkg := range flag.Args() {
		findImport(pkg)
	}
	cmd := exec.Command("dot", "-Tsvg")
	in, err := cmd.StdinPipe()
	check(err)
	out, err := cmd.StdoutPipe()
	cmd.Stderr = os.Stderr
	check(cmd.Start())

	fmt.Fprintf(in, "digraph {\n")
	keys := keys()
	for p, i := range keys {
		fmt.Fprintf(in, "\tN%d [label=%q,shape=box];\n", i, p)
	}
	for k, v := range pkgs {
		for _, p := range v {
			fmt.Fprintf(in, "\tN%d -> N%d [weight=1];\n", keys[k], keys[p])
		}
	}
	fmt.Fprintf(in, "}\n")
	in.Close()

	go browser.OpenReader(out)

	check(cmd.Wait())
}
Esempio n. 3
0
func main() {
	args := flag.Args()
	switch len(args) {
	case 0:
		check(browser.OpenReader(os.Stdin))
	case 1:
		check(browser.OpenFile(args[0]))
	default:
		usage()
	}
}
Esempio n. 4
0
func docs(c *cli.Context) {

	fmt.Println("Opening tenet documentation in a new browser window ...")

	var mdBuf bytes.Buffer
	if err := writeTenetDoc(c, "", &mdBuf); err != nil {
		common.OSErrf("%v", err)
		return
	}

	// Render markdown to HTML, and sanitise it to protect from
	// malicious tenets.
	htmlUnsafe := blackfriday.MarkdownBasic(mdBuf.Bytes())
	html := bluemonday.UGCPolicy().SanitizeBytes(htmlUnsafe)

	if err := browser.OpenReader(bytes.NewReader(html)); err != nil {
		common.OSErrf("opening docs in browser: %v", err)
		return
	}
}
Esempio n. 5
0
func main() {
	for _, pkg := range flag.Args() {
		findImport(pkg)
	}
	cmd := exec.Command("dot", "-Tsvg")
	in, err := cmd.StdinPipe()
	check(err)
	out, err := cmd.StdoutPipe()
	cmd.Stderr = os.Stderr
	check(cmd.Start())

	fmt.Fprintf(in, "digraph {\n")
	keys := keys()
	for p, i := range keys {
		fmt.Fprintf(in, "\tN%d [label=%q,shape=box];\n", i, p)
	}
	for k, v := range pkgs {
		for _, p := range v {
			fmt.Fprintf(in, "\tN%d -> N%d [weight=1];\n", keys[k], keys[p])
		}
	}
	fmt.Fprintf(in, "}\n")
	in.Close()

	if *stdout {
		// print to standard output
		io.Copy(os.Stdout, out)

	} else {
		// pipe output to browser
		ch := make(chan error)
		go func() {
			ch <- browser.OpenReader(out)

		}()
		check(cmd.Wait())
		if err := <-ch; err != nil {
			log.Fatalf("unable to open browser: %s", err)
		}
	}
}
Esempio n. 6
0
File: delta.go Progetto: joydo/delta
func main() {
	cli := flag.Bool("cli", false, "print the diff to stdout")
	gist := flag.Bool("gist", false, "upload gist to github")
	version := flag.Bool("version", false, "display delta version")
	install := flag.Bool("install", false, "install to gitconfig")
	uninstall := flag.Bool("uninstall", false, "remove from gitconfig")

	html := flag.Bool("html", false, "use with --cli to output html instead of text diff")

	flag.Parse()
	switch {
	case *version:
		fmt.Println("delta", VERSION)
		return
	case *install:
		installGit()
		return
	case *uninstall:
		uninstallGit()
		return
	}
	if flag.NArg() < 2 {
		flag.PrintDefaults()
		return
	}
	pathFrom := flag.Arg(0)
	pathTo := flag.Arg(1)
	pathBase := flag.Arg(1)
	if flag.NArg() > 2 {
		pathBase = flag.Arg(2)
	}

	config, err := loadConfig()
	if err != nil {
		fmt.Println("warning: error parsing .deltarc file")
	}

	d, err := diff(pathFrom, pathTo)
	if err != nil {
		os.Stderr.WriteString(err.Error())
		return
	}

	if err != nil {
		os.Stderr.WriteString(err.Error())
		return
	}
	if *cli && !*html {
		fmt.Println(formatter.ColoredText(d))
		return
	}
	page, err := render(d, pathFrom, pathTo, pathBase, config)
	switch {
	case *cli:
		page.WriteTo(os.Stdout)
	case *gist:
		uploadGist(page.Bytes())
	default:
		browser.OpenReader(page)
	}
}
Esempio n. 7
0
func main() {
	noTrimStructs = flag.Bool("noTrimStructs", false, "don't trim the contents of big structs to save space")
	includeExtlibs = flag.Bool("includeExtlibs", false, "include external libraries deeper than edge")
	stdlib := flag.String("graphStdlib", "edge", "graph standard library as well? yes, no or edge, where edge stops when it encounters a standard library.")

	excludeReg := flag.String("exclude", "", "exclude packages matching this regex")    // defaults to never-matching regexp
	matchReg := flag.String("match", ".*", "only include packages matching this regex") // defaults to always-matching regexp
	output := flag.String("output", "", "filename to output graphviz file to, such as graph.gv")

	ranksep = flag.Int("ranksep", 2, "distance between nodes in the graph")

	x := false
	graphStdlib = &x

	y := false
	skipStdlib = &y

	flag.Parse()
	pkg := flag.Args()

	if len(pkg) != 1 {
		fmt.Println("expected 1 argument, got", len(pkg))
		return
	}

	switch *stdlib {
	case "yes":
		*graphStdlib = true
		*skipStdlib = false
	case "edge":
		*graphStdlib = false
		*skipStdlib = false
	case "no":
		*graphStdlib = false
		*skipStdlib = true
	default:
		log.Fatalln("unknown graphStdlib value, expected 'yes', 'no' or 'edge'")
	}

	if *matchReg != "" {
		match = regexp.MustCompile(*matchReg)
	}
	if *excludeReg != "" {
		exclude = regexp.MustCompile(*excludeReg)
	}

	var err error
	cmd := exec.Command("dot", "-Tsvg")
	in, err := cmd.StdinPipe()
	if err != nil {
		panic(err)
	}
	out, err := cmd.StdoutPipe()
	cmd.Stderr = os.Stderr
	err = cmd.Start()
	if err != nil {
		panic(err)
	}

	inp := io.MultiWriter(in)

	if *output != "" {
		file, err := os.Create(*output)
		if err != nil {
			panic(err)
		}
		inp = io.MultiWriter(in, file)
	}

	// stdout for now
	drawGraph(inp, pkg[0])

	in.Close()
	//drawGraph(file, "github.com/drathier/saiph/grammar/parser")

	go browser.OpenReader(out)

	cmd.Wait()
}