-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cli): update the graph arg behavior #1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, I think we need to do a little update on text displayed to users.
@gsoltis updated, thanks for the review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one tiny nit, then ship it!
} | ||
|
||
func (d *graphValue) Set(value string) error { | ||
if value == _graphNoValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an unfortunate hack because of NoOptDefVal
appearing as a string in the usage text. Is it possible that we can use pflag.Flagset.Changed
instead of this? (I'd much prefer for this to be some sort of sigil value that a user is incapable of inputting.)
(I haven't yet looked into how pflag works so I don't know what is available when.)
func (r *run) generateDotGraph(taskGraph *dag.AcyclicGraph, outputFilename fs.AbsolutePath) error { | ||
graphString := string(taskGraph.Dot(&dag.DotOpts{ | ||
Verbose: true, | ||
DrawCycles: true, | ||
})) | ||
ext := outputFilename.Ext() | ||
if ext == ".html" { | ||
f, err := outputFilename.Create() | ||
if err != nil { | ||
return fmt.Errorf("error writing graph: %w", err) | ||
} | ||
defer f.Close() | ||
f.WriteString(`<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Graph</title> | ||
</head> | ||
<body> | ||
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2-pre.1/viz.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2-pre.1/full.render.js"></script> | ||
<script>`) | ||
f.WriteString("const s = `" + graphString + "`.replace(/\\_\\_\\_ROOT\\_\\_\\_/g, \"Root\").replace(/\\[root\\]/g, \"\");new Viz().renderSVGElement(s).then(el => document.body.appendChild(el)).catch(e => console.error(e));") | ||
f.WriteString(` | ||
</script> | ||
</body> | ||
</html>`) | ||
r.ui.Output("") | ||
r.ui.Output(fmt.Sprintf("✔ Generated task graph in %s", ui.Bold(outputFilename.ToString()))) | ||
if ui.IsTTY { | ||
if err := browser.OpenBrowser(outputFilename.ToString()); err != nil { | ||
r.ui.Warn(color.New(color.FgYellow, color.Bold, color.ReverseVideo).Sprintf("failed to open browser. Please navigate to file://%v", filepath.ToSlash(outputFilename.ToString()))) | ||
} | ||
} | ||
return nil | ||
} | ||
hasDot := hasGraphViz() | ||
if hasDot { | ||
dotArgs := []string{"-T" + ext[1:], "-o", outputFilename.ToString()} | ||
cmd := exec.Command("dot", dotArgs...) | ||
cmd.Stdin = strings.NewReader(graphString) | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("could not generate task graphfile %v: %w", outputFilename, err) | ||
} else { | ||
r.ui.Output("") | ||
r.ui.Output(fmt.Sprintf("✔ Generated task graph in %s", ui.Bold(outputFilename.ToString()))) | ||
} | ||
} else { | ||
r.ui.Output("") | ||
r.ui.Warn(color.New(color.FgYellow, color.Bold, color.ReverseVideo).Sprint(" WARNING ") + color.YellowString(" `turbo` uses Graphviz to generate an image of your\ngraph, but Graphviz isn't installed on this machine.\n\nYou can download Graphviz from https://graphviz.org/download.\n\nIn the meantime, you can use this string output with an\nonline Dot graph viewer.")) | ||
r.ui.Output("") | ||
r.ui.Output(graphString) | ||
} | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 The more things that get removed from run
the better our lives will be. This is great!
Updates the behavior of the
--graph
CLI flag and fixes a few bugs.This PR also:
--graph
CLI flagrun.go
Fixes #1286