-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
fastfetch: initial commit #2031
Conversation
Hardcoding the flags should be fine though, parsing help pages tends to be fragile in my experience. Update process involves simple regenerating it and doing a diff to check for new flag. This has worked pretty well so far. fastfetch -h | carapace-parse -n fastfetch -s "A neofetch-like tool for fetching system information and displaying them in a pretty
way""" Click to expandpackage cmd
import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "fastfetch",
Short: "A neofetch-like tool for fetching system information and displaying them in a pretty way",
Long: "https://github.com/fastfetch-cli/fastfetch",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().String("bar-border", "", "Whether to show a border around the bar. Default is true")
rootCmd.Flags().String("bar-char-elapsed", "", "Set the character to use in elapsed part. Default is '■'")
rootCmd.Flags().String("bar-char-total", "", "Set the character to use in total part. Default is '-'")
rootCmd.Flags().String("bar-width", "", "Set the width of the bar, in number of characters. Default is 10")
rootCmd.Flags().String("battery-dir", "", "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only")
rootCmd.Flags().String("battery-temp", "", "Detect and display Battery temperature if supported. Default is false")
rootCmd.Flags().String("battery-use-setup-api", "", "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only")
rootCmd.Flags().String("binary-prefix", "", "Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC")
rootCmd.Flags().String("bluetooth-show-disconnected", "", "Set if disconnected bluetooth devices should be printed. Default is false")
rootCmd.Flags().String("bright-color", "", "Set if the keys, title and ASCII logo should be printed in bright color. Default is true")
rootCmd.Flags().String("brightness-ddcci-sleep", "", "Set the sleep times (in ms) when sending DDC/CI requests. See <https://www.ddcutil.com/performance_options/#option-sleep-multiplier> for detail. Default is 10")
rootCmd.Flags().String("chafa", "", "Short for --logo-type chafa --logo <file>")
rootCmd.Flags().String("chafa-canvas-mode", "", "Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail")
rootCmd.Flags().String("chafa-color-space", "", "Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail")
rootCmd.Flags().String("chafa-dither-mode", "", "Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail")
rootCmd.Flags().String("chafa-fg-only", "", "Produce character-cell output using foreground colors only. See chafa document for detail")
rootCmd.Flags().String("chafa-symbols", "", "Specify character symbols to employ in final output. See chafa document for detail")
rootCmd.Flags().String("chassis-use-wmi", "", "Set if WMI query should be used on Windows, which detects more information but slower. Default is false")
rootCmd.Flags().String("color", "", "Set the color of both the keys and title")
rootCmd.Flags().String("color-keys", "", "Set the color of the keys")
rootCmd.Flags().String("color-title", "", "Set the color of the title")
rootCmd.Flags().String("colors-padding-left", "", "Set the number of white spaces to print before the symbol. Default is 0")
rootCmd.Flags().String("colors-symbol", "", "Set the symbol to be printed by Colors module. Default is block")
rootCmd.Flags().String("command-key", "", "Set the module key to display")
rootCmd.Flags().String("command-shell", "", "Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix")
rootCmd.Flags().String("command-text", "", "Set the command text to be executed")
rootCmd.Flags().String("cpu-freq-ndigits", "", "Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2")
rootCmd.Flags().String("cpu-temp", "", "Detect and display CPU temperature if supported. Default is false")
rootCmd.Flags().String("cpuusage-separate", "", "Display CPU usage per CPU logical core, instead of an average result. Default is false")
rootCmd.Flags().String("data", "", "Short for --logo-type data --logo <data>")
rootCmd.Flags().String("data-raw", "", "Short for --logo-type data-raw --logo <data>")
rootCmd.Flags().String("de-slow-version-detection", "", "Set if DE version should be detected with slow operations. Default is false")
rootCmd.Flags().String("disk-folders", "", "A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is \"/:/home\" (\"C:\\;D:\\ ...\" on Windows)")
rootCmd.Flags().String("disk-show-external", "", "Set if external volume should be printed. Default is true")
rootCmd.Flags().String("disk-show-hidden", "", "Set if hidden volumes should be printed. Default is false")
rootCmd.Flags().String("disk-show-readonly", "", "Set if read only volumes should be printed. Default is false")
rootCmd.Flags().String("disk-show-regular", "", "Set if regular volume should be printed. Default is true")
rootCmd.Flags().String("disk-show-subvolumes", "", "Set if subvolumes should be printed. Default is false")
rootCmd.Flags().String("disk-show-unknown", "", "Set if unknown (unable to detect sizes) volumes should be printed. Default is false")
rootCmd.Flags().String("disk-use-available", "", "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false")
rootCmd.Flags().String("diskio-name-prefix", "", "Show disks with given name prefix only. Default is empty")
rootCmd.Flags().String("display-compact-type", "", "Set if all displays should be printed in one line. Default is none")
rootCmd.Flags().String("display-detect-name", "", "Set if display name should be detected and printed (if supported). Default is false")
rootCmd.Flags().String("ds-force-drm", "", "Set if only DRM should be used to detect displays. Default is false. Linux only")
rootCmd.Flags().String("escape-bedrock", "", "On Bedrock Linux, whether to escape the bedrock jail")
rootCmd.Flags().String("file", "", "Short for --logo-type file --logo <file>")
rootCmd.Flags().String("file-raw", "", "Short for --logo-type file-raw --logo <file>")
rootCmd.Flags().String("gen-config", "", "Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf`")
rootCmd.Flags().String("gen-config-force", "", "Generate a sample config file in the default path. Overwrite the existing one")
rootCmd.Flags().String("gpu-force-vulkan", "", "Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false")
rootCmd.Flags().String("gpu-hide-type", "", "Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none")
rootCmd.Flags().String("gpu-temp", "", "Detect and display GPU temperature if supported. Default is false")
rootCmd.Flags().String("gpu-use-nvml", "", "Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false")
rootCmd.Flags().StringP("help", "h", "", "Show help for a specific command")
rootCmd.Flags().BoolP("help:", "h", false, "Show this message")
rootCmd.Flags().String("hide-cursor", "", "Whether to hide the cursor during the run")
rootCmd.Flags().String("iterm", "", "Short for --logo-type iterm --logo <file>")
rootCmd.Flags().String("key-width", "", "Align the width of keys to <num> characters")
rootCmd.Flags().String("kitty", "", "Short for --logo-type kitty --logo <file>")
rootCmd.Flags().String("lib-DBus", "", "Bluetooth, Player & Media detection")
rootCmd.Flags().String("lib-DConf", "", "Needed for values that are only stored in DConf + Fallback for GSettings")
rootCmd.Flags().String("lib-PCI", "", "GPU output")
rootCmd.Flags().String("lib-X11", "", "X11 sessions for better display detection and faster WM detection")
rootCmd.Flags().String("lib-XFConf", "", "Needed for XFWM theme and XFCE Terminal font")
rootCmd.Flags().String("lib-Xrandr", "", "X11 sessions for better display detection and faster WM detection")
rootCmd.Flags().String("lib-chafa", "", "Image output as ascii art")
rootCmd.Flags().String("lib-ddcutil", "", "Used for brightness detection of external displays")
rootCmd.Flags().String("lib-egl", "", "Needed by the OpenGL module for gl context creation")
rootCmd.Flags().String("lib-freetype", "", "Used for Termux font detection")
rootCmd.Flags().String("lib-gio", "", "Needed for values that are only stored GSettings")
rootCmd.Flags().String("lib-glx", "", "Needed by the OpenGL module for gl context creation")
rootCmd.Flags().String("lib-imagemagick", "", "Images in terminal using sixel or kitty graphics protocol")
rootCmd.Flags().Bool("lib-nm:", false, "NetworkManager. Used for Wifi detection")
rootCmd.Flags().String("lib-opencl", "", "OpenCL module")
rootCmd.Flags().String("lib-osmesa", "", "Needed by the OpenGL module for gl context creation")
rootCmd.Flags().String("lib-pulse", "", "Pulseaudio. Used for Sound detection")
rootCmd.Flags().String("lib-rpm", "", "Slower fallback for rpm package count")
rootCmd.Flags().String("lib-sqlite3", "", "Needed for pkg & rpm package count")
rootCmd.Flags().String("lib-vulkan", "", "Vulkan module & fallback for GPU output")
rootCmd.Flags().String("lib-wayland", "", "Better display performance and output in wayland sessions")
rootCmd.Flags().String("lib-xcb", "", "X11 sessions for better display detection and faster WM detection")
rootCmd.Flags().String("lib-xcb-randr", "", "X11 sessions for better display detection and faster WM detection")
rootCmd.Flags().String("lib-z", "", "Libz. Faster image output when using kitty graphics protocol")
rootCmd.Flags().Bool("list-config-paths:", false, "List search paths of config files")
rootCmd.Flags().Bool("list-data-paths:", false, "List search paths of presets and logos")
rootCmd.Flags().Bool("list-features:", false, "List the supported features fastfetch was compiled with (mainly for development)")
rootCmd.Flags().Bool("list-logos:", false, "List available logos")
rootCmd.Flags().Bool("list-modules:", false, "List available modules")
rootCmd.Flags().Bool("list-presets:", false, "List presets fastfetch knows about; they can be loaded with --load-config (+)")
rootCmd.Flags().StringP("load-config", "c", "", "Load a config file or preset (+)")
rootCmd.Flags().String("localip-compact", "", "Show all IPs in one line. Default is false")
rootCmd.Flags().String("localip-default-route-only", "", "Show the interface that is used for default routing only. Default is true on non-android platforms")
rootCmd.Flags().String("localip-name-prefix", "", "Show interfaces with given interface name prefix only. Default is empty")
rootCmd.Flags().String("localip-show-ipv4", "", "Show IPv4 addresses in local ip module. Default is true")
rootCmd.Flags().String("localip-show-ipv6", "", "Show IPv6 addresses in local ip module. Default is false")
rootCmd.Flags().String("localip-show-loop", "", "Show loop back addresses (127.0.0.1) in local ip module. Default is false")
rootCmd.Flags().String("localip-show-mac", "", "Show mac addresses in local ip module. Default is false")
rootCmd.Flags().StringP("logo", "l", "", "Set the logo; if default, the name of a builtin logo or a path to a file")
rootCmd.Flags().String("logo-color-[1-9]", "", "Overwrite a color in the logo")
rootCmd.Flags().String("logo-height", "", "Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol")
rootCmd.Flags().String("logo-padding", "", "Set the padding on the left and the right of the logo")
rootCmd.Flags().String("logo-padding-left", "", "Set the padding on the left of the logo")
rootCmd.Flags().String("logo-padding-right", "", "Set the padding on the right of the logo")
rootCmd.Flags().String("logo-padding-top", "", "Set the padding on the top of the logo")
rootCmd.Flags().String("logo-print-remaining", "", "Whether to print the remaining logo, if it has more lines than modules to display")
rootCmd.Flags().String("logo-recache", "", "If true, regenerate image logo cache")
rootCmd.Flags().String("logo-separate", "", "If true, print modules at bottom of the logo")
rootCmd.Flags().String("logo-type", "", "Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa")
rootCmd.Flags().String("logo-width", "", "Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol")
rootCmd.Flags().String("migrate-config", "", "Migrate old flag based config file to new JSONC format. Optional param `path` is the file path that new file should be write to")
rootCmd.Flags().String("netio-default-route-only", "", "Show the interfac that is used for default routing only. Default is true on non-android platforms")
rootCmd.Flags().String("netio-name-prefix", "", "Show interfaces with given name prefix only. Default is empty")
rootCmd.Flags().String("no-buffer", "", "Set if the stdout application buffer should be disabled. Default is false")
rootCmd.Flags().String("opengl-library", "", "Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto")
rootCmd.Flags().String("os-file", "", "Set the path to the file containing OS information. Linux only")
rootCmd.Flags().String("packages-winget", "", "Set if winget package count should be detected. Default is false")
rootCmd.Flags().String("percent-ndigits", "", "Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0")
rootCmd.Flags().String("percent-type", "", "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 9")
rootCmd.Flags().String("pipe", "", "Disable logo and all escape sequences")
rootCmd.Flags().String("player-name", "", "The name of the player to use for module Media and Player. Linux only")
rootCmd.Flags().Bool("print-config-system:", false, "Print the default system config")
rootCmd.Flags().Bool("print-config-user:", false, "Print the default user config")
rootCmd.Flags().Bool("print-logos:", false, "Print available logos")
rootCmd.Flags().Bool("print-structure:", false, "Print the default structure")
rootCmd.Flags().String("processing-timeout", "", "Set the timeout (ms) when waiting for child processes. Default is 1000")
rootCmd.Flags().String("publicip-timeout", "", "Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)")
rootCmd.Flags().String("publicip-url", "", "The URL of public IP detection server to be used.")
rootCmd.Flags().String("separator", "", "Set the separator between key and value. Default is a colon with a space")
rootCmd.Flags().String("separator-string", "", "Set the string printed by the separator module")
rootCmd.Flags().String("set", "", "Hard set the value of a key")
rootCmd.Flags().String("set-keyless", "", "Hard set the value of a key, but don't print the key or the separator")
rootCmd.Flags().String("show-errors", "", "Print occurring errors")
rootCmd.Flags().String("sixel", "", "Short for --logo-type sixel --logo <file>")
rootCmd.Flags().String("size-max-prefix", "", "Set the largest binary prefix to use when formatting sizes. Default is YB")
rootCmd.Flags().String("size-ndigits", "", "Set the number of digits to keep after the decimal point when formatting sizes")
rootCmd.Flags().String("sound-type", "", "Set what type of sound devices should be printed. Should be either main, active or all. Default is main")
rootCmd.Flags().String("stat", "", "Show time usage (in ms) for individual modules")
rootCmd.Flags().StringP("structure", "s", "", "Set the structure of the fetch. Must be a colon separated list of keys. Use `fastfetch --list-modules` to see the ones available.")
rootCmd.Flags().String("temperature-unit", "", "Set the unit of the temperature. Must be one of C, F and K. Default is C")
rootCmd.Flags().String("thread", "", "Use separate threads to send HTTP requests")
rootCmd.Flags().String("title-color-at", "", "Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`)")
rootCmd.Flags().String("title-color-host", "", "Set color of the host name (right part). Default is empty (use color of `--color-title`)")
rootCmd.Flags().String("title-color-user", "", "Set color of the user name (left part). Default is empty (use color of `--color-title`).")
rootCmd.Flags().String("title-fqdn", "", "Set if the title should use fully qualified domain name. Default is false")
rootCmd.Flags().BoolP("version:", "v", false, "Show the version of fastfetch")
rootCmd.Flags().String("weather-location", "", "Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`).")
rootCmd.Flags().String("weather-output-format", "", "The output weather format to be used. It must be URI encoded.")
rootCmd.Flags().String("weather-timeout", "", "Time in milliseconds to wait for the weather server to respond. Default is disabled (0)")
rootCmd.Flags().String("wm-detect-plugin", "", "Set if window manager plugin should be detected on supported platforms. Default is false")
rootCmd.Flags().String("wmi-timeout", "", "Set the timeout (ms) for WMI queries. Windows only. Default is 5000")
} |
Anything in
"config": carapace.ActionExecCommand("fastfetch", "--list-presets", "false")(func(output []byte) carapace.Action {
presets = strings.Split(strings.TrimRight(string(output), "\n"), "\n")
return carapace.ActionValues(presets...)
}), It also handles environment variables, work directory (e.g. with Chdir) and errors correctly. |
I have full control of fastfetch project. I don't plan to change the basic format of help message of fastfetch. And even if I do, I will submit PRs to fix it.
There are some issues in the generated code I found:
In addition, as I said before, the number of flags of fastfetch keeps growing, and there are changes and corrections in almost every release. Maintaining 100+ flags in my repo is already hard. Maintaining them in a different repo that I have no control is much harder. A big no for me.
Any changes that duplicate the content of fastfetch help message are things I want to avoid.
Thanks for pointing out this. I will have a try. |
The modules are static, hard-coded in fastfetch code. They won't change unless you upgrade fastfetch. I don't want to add the |
All fastfetch boolean flags accept two optional values How can I do it without define all of them explicitly in |
What's the difference between |
f8ecc73
to
5e018c8
Compare
Undestandable. Just doesn't fit so well with how the other completers are done.
Generating yaml for this at runtime might be a good option here.
No enforcement possible at the moment. Up to the user to use it correctly.
Optional arguments for flags are only supported in the attached form (
Completion is defined explicitly in carapace. As there is no file completion fallback this should be the default.
Flags are case-sensitive. Case-insensitive matching can be enabled with
// command pos1 pos2 posAny posAny -- dash1 dash2 dashAny dashAny
carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionValues("pos1"),
carapace.ActionValues("pos2"),
)
carapace.Gen(rootCmd).PositionalAnyCompletion(
carapace.ActionValues("posAny"),
)
carapace.Gen(rootCmd).DashCompletion(
carapace.ActionValues("dash1"),
carapace.ActionValues("dash2"),
)
carapace.Gen(rootCmd).DashAnyCompletion(
carapace.ActionValues("dashAny"),
) |
That would make sense if I use it personally, but I don't think that making users install completer tool just for my project is a good idea. Anyway, I have made it to parse JSON ( generated by fastfetch program too ), which make the code much cleaner. The JSON file is here: https://github.com/fastfetch-cli/fastfetch/blob/dev/src/data/help.json. It's also used for printing help message of fastfetch and will be actively maintained. |
8e6ffc7
to
7327581
Compare
Fixed, but I'm unable to test it |
I was able to build carapace without issues, but now it keeps complaining
Strange |
Did you run |
thanks |
Thanks for your great project! This PR tries to add support for my project fastfetch
Fastfetch supports more than 100 flags, and it's still growing, so I don't want to hard-code these flags, and ends up with parsing its help message. It's actually my first time to write go code and I know the implementation needs more polish. I'm opening this PR to get some advices.