Esempio n. 1
0
func process() int {
	options, err := getOptions()
	if err != nil {
		return 1
	}
	factory := goimport.ParseRelation(
		options.InputDir,
		options.SeekPath,
		options.PlotLeaf,
	)
	if factory == nil {
		errorf("inputdir does not exist.\n go get %s", options.InputDir)
		return 1
	}
	root := factory.GetRoot()
	if !root.HasFiles() {
		errorf("%s has no .go files\n", root.ImportPath)
		return 1
	}
	if 0 > options.Depth {
		errorf("-d or --depth should have positive int\n")
		return 1
	}
	output := getOutputWriter(options.OutputFile)
	if options.UseMetrics {
		metrics_writer := metrics.New(output)
		metrics_writer.Plot(pathToNode(factory.GetAll()))
		return 0
	}

	writer := dotwriter.New(output)
	writer.MaxDepth = options.Depth
	if options.Reversed == "" {
		writer.PlotGraph(root)
		return 0
	}
	writer.Reversed = true

	rroot := factory.Get(options.Reversed)
	if rroot == nil {
		errorf("-r %s does not exist.\n ", options.Reversed)
		return 1
	}
	if !rroot.HasFiles() {
		errorf("-r %s has no go files.\n ", options.Reversed)
		return 1
	}

	writer.PlotGraph(rroot)
	return 0
}
Esempio n. 2
0
func main() {
	options := getOptions()
	factory := goimport.ParseRelation(
		options.InputDir,
		options.SeekPath,
		options.PlotLeaf,
	)
	root := factory.GetRoot()
	if !root.HasFiles() {
		fmt.Fprintf(os.Stderr, "%s has no .go files\n", root.ImportPath)
		os.Exit(1)
	}
	if 0 > options.Depth {
		fmt.Fprintf(os.Stderr, "-d or --depth should have positive int\n")
		os.Exit(1)
	}
	output := getOutputWriter(options.OutputFile)
	if options.UseMetrics {
		metrics_writer := metrics.New(output)

		metrics_writer.Plot(pathToNode(factory.GetAll()))
		return
	}

	writer := dotwriter.New(output)
	writer.MaxDepth = options.Depth
	if options.Reversed == "" {
		writer.PlotGraph(root)
		return
	}
	writer.Reversed = true

	rroot := factory.Get(options.Reversed)
	if !rroot.HasFiles() {

		os.Exit(1)
	}

	writer.PlotGraph(rroot)

}