Skip to content
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

Add support for formatter specification #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FBIGlowie
Copy link

Hello, this PR's goal is to add the option to specify which formatter to use, mainly nixfmt and alejandra.

I'm not sure what to do about the tests since the of course don't pass.

If there is a problem, let me know, this is like the 2nd go project I have every interacted with so I'm very new 😄.

@FBIGlowie FBIGlowie marked this pull request as ready for review November 30, 2024 04:19
@aksiksi
Copy link
Owner

aksiksi commented Dec 1, 2024

Thanks for the contribution! I will review within the next few days.

@@ -123,6 +123,7 @@ type Generator struct {
RemoveVolumes bool
NoCreateRootTarget bool
AutoFormat bool
Formatter string
Copy link
Owner

@aksiksi aksiksi Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format/line this up with the other struct fields.

Note for next time: You can either set this up in your editor, or use go fmt to format all files:

go fmt ./...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Owner

@aksiksi aksiksi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, and sorry for the delay in reviewing this!

General comments

@@ -17,6 +20,8 @@
version = "0.3.2-pre";
# LINT.ThenChange(main.go:version)
in {
# Formatter to be used by helped func
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment.

if err != nil {
return nil, fmt.Errorf("'nixfmt' not found in $PATH: %w", err)
return nil, fmt.Errorf("%w not found in $PATH: %w", formatter, err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better error message:

fmt.Errorf("configured formatter %q not found in $PATH: %w", formatter, err)

%q will wrap the string in double quotes (").

Also, %w is only used to wrap errors in Go.

@@ -40,7 +40,7 @@ var createRootTarget = flag.Bool("create_root_target", true, "if set, a root sys
var defaultStopTimeout = flag.Duration("default_stop_timeout", defaultSystemdStopTimeout, "default stop timeout for generated container services.")
var build = flag.Bool("build", false, "if set, generated container build systemd services will be enabled.")
var writeNixSetup = flag.Bool("write_nix_setup", true, "if true, Nix setup code is written to output (runtime, DNS, autoprune, etc.)")
var autoFormat = flag.Bool("auto_format", false, `if true, Nix output will be formatted using "nixfmt" (must be present in $PATH).`)
var formatter = flag.String("formatter", "", `if specified, Nix output will be formatted by formatter specified, supported are nixfmt and alejandra (must be present in $PATH).`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

flag.String("formatter", "nixfmt", `if specified, Nix output will be formatted by the Nix formatter specified (must be present in $PATH). supported options are: "nixfmt" and "alejandra"`)

@@ -51,7 +51,7 @@ func (*OsGetWd) GetWd() (string, error) {

func main() {
flag.Parse()

fmt.Println(*formatter)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

@@ -40,7 +40,7 @@ var createRootTarget = flag.Bool("create_root_target", true, "if set, a root sys
var defaultStopTimeout = flag.Duration("default_stop_timeout", defaultSystemdStopTimeout, "default stop timeout for generated container services.")
var build = flag.Bool("build", false, "if set, generated container build systemd services will be enabled.")
var writeNixSetup = flag.Bool("write_nix_setup", true, "if true, Nix setup code is written to output (runtime, DNS, autoprune, etc.)")
var autoFormat = flag.Bool("auto_format", false, `if true, Nix output will be formatted using "nixfmt" (must be present in $PATH).`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the auto_format flag? But change the help text to:

`if true, Nix output will be formatted using the formatter passed to the "formatter" flag (default: "nixfmt")`

@FBIGlowie
Copy link
Author

Thank thanks, I will edit within a few days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants