-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
Conversation
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 |
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.
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 ./...
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.
👍
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.
Thanks for the contribution, and sorry for the delay in reviewing this!
General comments
- You'll need to update this test to pass in a
formatter
: https://github.com/aksiksi/compose2nix/blob/main/nix_test.go#L103
@@ -17,6 +20,8 @@ | |||
version = "0.3.2-pre"; | |||
# LINT.ThenChange(main.go:version) | |||
in { | |||
# Formatter to be used by helped func |
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.
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) |
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.
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).`) |
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.
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) |
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.
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).`) |
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.
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")`
Thank thanks, I will edit within a few days |
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 😄.