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

Feat/added toml supersim config closes #104 #295

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

Conversation

s29papi
Copy link
Contributor

@s29papi s29papi commented Dec 5, 2024

Description

This pull request implements significant improvements to the configuration handling of the application. The changes include the addition of a TOML configuration file that is parsed, allowing values to be passed in as command-line arguments. The configuration values from the TOML file take precedence over those provided via CLI flags, ensuring a more flexible and user-friendly configuration experience.

Tests

Comprehensive tests have been added to verify the correct parsing of the TOML file and the proper application of configuration values. The tests ensure that:

  • The application correctly reads and applies values from the TOML file.
  • CLI arguments are overridden by values from the TOML file when both are provided.
  • All edge cases, such as missing or default values, are handled appropriately.

Additional context

These improvements address the need for a more robust configuration management system, allowing users to define their settings in a structured format while still providing the flexibility of command-line overrides. This change enhances usability and aligns with best practices for configuration management.

Metadata

@s29papi s29papi requested a review from a team as a code owner December 5, 2024 09:39
@s29papi s29papi changed the title Feat/added toml supersim config Feat/added toml supersim config closes #104 Dec 5, 2024
Copy link
Contributor

@jakim929 jakim929 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 PR! Mostly looks great Left some comments

  1. Explicitly passed flags should always override file based config
  2. Not have separate type definitions for CLIConfig
  3. Some nit readme updates

Comment on lines +34 to +35
### 3. Configure `supersim` (Optional)

Copy link
Contributor

Choose a reason for hiding this comment

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

this readme section is great but can we move it down to a separate section ## Configuration after ## First Steps. The Getting Started should stay as short as possible

Comment on lines +167 to 175
type TOMLConfig struct {
AdminPort uint64 `toml:"admin_port"`

LogsDirectory: ctx.String(LogsDirectoryFlagName),
L1Port uint64 `toml:"l1_port"`
L2StartingPort uint64 `toml:"l2_starting_port"`

L1Host: ctx.String(L1HostFlagName),
L2Host: ctx.String(L2HostFlagName),
}
InteropAutoRelay bool `toml:"interop_autorelay"`
InteropDelay uint64 `toml:"interop_delay"`

Copy link
Contributor

Choose a reason for hiding this comment

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

TOMLConfig and ForkTOMLConfig should be combined with the ForkCLIConfig and CLIConfig. I think we can just add struct tags to the CLIConfig and ForkCLIConfig.

Comment on lines +35 to +36
*.toml
!*.toml.template
Copy link
Contributor

Choose a reason for hiding this comment

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

can probably remove this - People primarily consume this package as a binary so it's rare that people will directly try to commit their toml to the repo

@@ -244,3 +254,87 @@ func validateHost(host string) error {

return nil
}

func readTOMLConfig(cfg *CLIConfig) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe rename to "applyTOMLConfig" since this does more than reading

return nil
}

func populateFromCLIContext(cfg *CLIConfig, ctx *cli.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

RC: this function makes it so that if the TOML config is set, the cli flags can't override it. Should update it so that the explicit flags passed to CLI always take precedence. That would align better with the expected behavior of most CLIs (explicit flags override file base config)

We can just remove the checks for the default values (ie. cfg.L1Port == 0)

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.

Config Improvements
2 participants