Skip to content

Add more configuration options to confique::FormatOptions #49

Open
mtfwvi wants to merge 6 commits intoLukasKalbertodt:mainfrom
mtfwvi:template-more-config-options
Open

Add more configuration options to confique::FormatOptions #49
mtfwvi wants to merge 6 commits intoLukasKalbertodt:mainfrom
mtfwvi:template-more-config-options

Conversation

@mtfwvi
Copy link

@mtfwvi mtfwvi commented Jan 8, 2026

I've added two new options to FormatOptions:

  • include_default_or_required_comment (controls whether to include comments about required/default values) and
  • comment_out_default_values (controls whether default values are commented out or written as active fields).

Both default to true.

To achieve comment_out_default_values, I've added a new field method to the Formatter trait for emitting a field with its value.

Some Examples:

  • Default Options:
toml::template::<Conf>() yaml::template::<Conf>() json5::template::<Conf>()
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#
# Default value: 8080
#port = 8080

# Bind address.
#
# Default value: "127.0.0.1"
#address = "127.0.0.1"

[log]
# Default value: true
#stdout = true

#file =

# Default value: ["debug"]
#ignored_modules = ["debug"]
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#
# Default value: 8080
#port: 8080

# Bind address.
#
# Default value: 127.0.0.1
#address: 127.0.0.1

log:
  # Default value: true
  #stdout: true

  #file:

  # Default value: [debug]
  #ignored_modules: [debug]
{
  // Port to listen on.
  //
  // Can also be specified via environment variable `PORT`.
  //
  // Default value: 8080
  //port: 8080,

  // Bind address.
  //
  // Default value: "127.0.0.1"
  //address: "127.0.0.1",

  log: {
    // Default value: true
    //stdout: true,

    //file: ,

    // Default value: ["debug"]
    //ignored_modules: ["debug"],
  },
}
  • FormatOptions::comment_out_default_values = false
toml::template::<Conf>() yaml::template::<Conf>() json5::template::<Conf>()
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#
# Default value: 8080
port = 8080

# Bind address.
#
# Default value: "127.0.0.1"
address = "127.0.0.1"

[log]
# Default value: true
stdout = true

#file =

# Default value: ["debug"]
ignored_modules = ["debug"]
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#
# Default value: 8080
port: 8080

# Bind address.
#
# Default value: 127.0.0.1
address: 127.0.0.1

log:
  # Default value: true
  stdout: true

  #file:

  # Default value: [debug]
  ignored_modules: [debug]
{
  // Port to listen on.
  //
  // Can also be specified via environment variable `PORT`.
  //
  // Default value: 8080
  port: 8080,

  // Bind address.
  //
  // Default value: "127.0.0.1"
  address: "127.0.0.1",

  log: {
    // Default value: true
    stdout: true,

    //file: ,

    // Default value: ["debug"]
    ignored_modules: ["debug"],
  },
}
  • FormatOptions::include_default_or_required_comment = false
toml::template::<Conf>() yaml::template::<Conf>() json5::template::<Conf>()
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#port = 8080

# Bind address.
#address = "127.0.0.1"

[log]
#stdout = true

#file =

#ignored_modules = ["debug"]
# Port to listen on.
#
# Can also be specified via environment variable `PORT`.
#port: 8080

# Bind address.
#address: 127.0.0.1

log:
  #stdout: true

  #file:

  #ignored_modules: [debug]
{
  // Port to listen on.
  //
  // Can also be specified via environment variable `PORT`.
  //port: 8080,

  // Bind address.
  //address: "127.0.0.1",

  log: {
    //stdout: true,

    //file: ,

    //ignored_modules: ["debug"],
  },
}

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.

1 participant