|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/carapace-sh/carapace" |
| 5 | + "github.com/carapace-sh/carapace-bin/pkg/actions/net" |
| 6 | + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/d2" |
| 7 | + "github.com/spf13/cobra" |
| 8 | +) |
| 9 | + |
| 10 | +var rootCmd = &cobra.Command{ |
| 11 | + Use: "d2", |
| 12 | + Short: "compiles and renders d2 diagrams into svgs", |
| 13 | + Long: "https://d2lang.com/", |
| 14 | + Run: func(cmd *cobra.Command, args []string) {}, |
| 15 | +} |
| 16 | + |
| 17 | +func Execute() error { |
| 18 | + return rootCmd.Execute() |
| 19 | +} |
| 20 | +func init() { |
| 21 | + carapace.Gen(rootCmd).Standalone() |
| 22 | + |
| 23 | + rootCmd.Flags().String("animate-interval", "", "multiple boards are packaged as 1 SVG") |
| 24 | + rootCmd.Flags().String("ascii-mode", "", "ASCII rendering mode for text outputs") |
| 25 | + rootCmd.Flags().String("browser", "", "browser executable that watch opens") |
| 26 | + rootCmd.Flags().BoolP("bundle", "b", false, "bundle all assets and layers into the output file") |
| 27 | + rootCmd.Flags().BoolP("center", "c", false, "center the SVG in the containing viewbox") |
| 28 | + rootCmd.Flags().Bool("check", false, "check that the specified files are formatted correctly") |
| 29 | + rootCmd.Flags().String("dark-theme", "", "the theme to use when the viewer's browser is in dark mode") |
| 30 | + rootCmd.Flags().BoolP("debug", "d", false, "print debug logs") |
| 31 | + rootCmd.Flags().String("font-bold", "", "path to .ttf file to use for the bold font") |
| 32 | + rootCmd.Flags().String("font-italic", "", "path to .ttf file to use for the italic font") |
| 33 | + rootCmd.Flags().String("font-mono", "", "path to .ttf file to use for the monospace font") |
| 34 | + rootCmd.Flags().String("font-mono-bold", "", "path to .ttf file to use for the monospace bold font") |
| 35 | + rootCmd.Flags().String("font-mono-italic", "", "path to .ttf file to use for the monospace italic font") |
| 36 | + rootCmd.Flags().String("font-mono-semibold", "", "path to .ttf file to use for the monospace semibold font") |
| 37 | + rootCmd.Flags().String("font-regular", "", "path to .ttf file to use for the regular font") |
| 38 | + rootCmd.Flags().String("font-semibold", "", "path to .ttf file to use for the semibold font") |
| 39 | + rootCmd.Flags().Bool("force-appendix", false, "add an appendix to SVG exports") |
| 40 | + rootCmd.Flags().StringP("host", "h", "", "host listening address when used with watch") |
| 41 | + rootCmd.Flags().Bool("img-cache", false, "images used in icons are cached for subsequent compilations") |
| 42 | + rootCmd.Flags().StringP("layout", "l", "", "the layout engine used") |
| 43 | + rootCmd.Flags().Bool("no-xml-tag", false, "omit XML tag (<?xml ...?>) from output SVG files") |
| 44 | + rootCmd.Flags().Bool("omit-version", false, "omit D2 version from generated image") |
| 45 | + rootCmd.Flags().String("pad", "", "pixels padded around the rendered diagram") |
| 46 | + rootCmd.Flags().StringP("port", "p", "", "port listening address when used with watch") |
| 47 | + rootCmd.Flags().String("salt", "", "Add a salt value to ensure the output uses unique IDs") |
| 48 | + rootCmd.Flags().String("scale", "", "scale the output") |
| 49 | + rootCmd.Flags().BoolP("sketch", "s", false, "render the diagram to look like it was sketched by hand") |
| 50 | + rootCmd.Flags().String("stdout-format", "", "output format when writing to stdout") |
| 51 | + rootCmd.Flags().String("target", "", "target board to render") |
| 52 | + rootCmd.Flags().StringP("theme", "t", "", "the diagram theme ID") |
| 53 | + rootCmd.Flags().String("timeout", "", "the maximum number of seconds that D2 runs") |
| 54 | + rootCmd.Flags().BoolP("version", "v", false, "get the version") |
| 55 | + rootCmd.Flags().BoolP("watch", "w", false, "watch for changes to input and live reload") |
| 56 | + |
| 57 | + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ |
| 58 | + "ascii-mode": carapace.ActionValuesDescribed( |
| 59 | + "standard", "basic ASCII chars", |
| 60 | + "extended", "Unicode chars", |
| 61 | + ), |
| 62 | + "browser": carapace.Batch( |
| 63 | + carapace.ActionExecutables(), |
| 64 | + carapace.ActionFiles(), |
| 65 | + ).ToA(), |
| 66 | + "dark-theme": d2.ActionThemes(d2.ThemeOpts{Dark: true}), |
| 67 | + "font-bold": carapace.ActionFiles(".ttf"), |
| 68 | + "font-italic": carapace.ActionFiles(".ttf"), |
| 69 | + "font-mono": carapace.ActionFiles(".ttf"), |
| 70 | + "font-mono-bold": carapace.ActionFiles(".ttf"), |
| 71 | + "font-mono-italic": carapace.ActionFiles(".ttf"), |
| 72 | + "font-mono-semibold": carapace.ActionFiles(".ttf"), |
| 73 | + "font-regular": carapace.ActionFiles(".ttf"), |
| 74 | + "font-semibold": carapace.ActionFiles(".ttf"), |
| 75 | + "layout": d2.ActionLayouts(), |
| 76 | + "pad": carapace.ActionValues(), |
| 77 | + "port": net.ActionPorts(), |
| 78 | + "stdout-format": carapace.ActionValues("svg", "png", "ascii", "txt", "pdf", "pptx", "gif"), |
| 79 | + "target": carapace.ActionValues(), // TODO |
| 80 | + "theme": d2.ActionThemes(d2.ThemeOpts{}.Default()), |
| 81 | + }) |
| 82 | + |
| 83 | + carapace.Gen(rootCmd).PositionalCompletion( |
| 84 | + carapace.ActionFiles(".d2"), |
| 85 | + ) |
| 86 | + |
| 87 | + carapace.Gen(rootCmd).PositionalAnyCompletion( |
| 88 | + carapace.ActionFiles(), |
| 89 | + ) |
| 90 | +} |
0 commit comments