jesec / flood

A modern web UI for various torrent clients with a Node.js backend and React frontend.
https://flood.js.org
GNU General Public License v3.0
2.08k stars 127 forks source link

Add config file flag #717

Open rasmus-kirk opened 6 months ago

rasmus-kirk commented 6 months ago

Adds a config file flag to load in config parameters from a JSON file.

Description

Lets users load in command line configuration files as a JSON file using the -c or --config flags. Options compose, so options set by the command line and the config will combine. If the same option is set by both, the command line value takes precedence. Provided file must be valid JSON and have the .json file extension. Tested by running with the --config flag set to a file containing:

{
  "port": 3001
}

My use-case is that I'm using nix to configure Flood and providing the secret values for authentication as command line arguments would leak them to the nix store which means non-root users would be able to see the secrets.

trim21 commented 6 months ago

thanks for your contribution, I'll review and test this when I have spare time.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (20a672a) 73.15% compared to head (17170bb) 73.13%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #717 +/- ## ========================================== - Coverage 73.15% 73.13% -0.02% ========================================== Files 62 62 Lines 11375 11375 Branches 959 963 +4 ========================================== - Hits 8321 8319 -2 - Misses 3040 3042 +2 Partials 14 14 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

trim21 commented 6 months ago

is it possible to support yaml as well?

rasmus-kirk commented 6 months ago

is it possible to support yaml as well?

Not really, we can give it a custom parse function, but even if that's doable, the file will still have to have the .json file extension.

trim21 commented 6 months ago

I saw config.txt in this PR

https://github.com/yargs/yargs/pull/321/files

rasmus-kirk commented 6 months ago

I must be wrong then, well, in that case it should be possible given that we import a yaml parser. If you think yaml support is important I can try adding it later this month. Should we have two flags then, one for each, or what do you think?

trim21 commented 6 months ago

I must be wrong then, well, in that case it should be possible given that we import a yaml parser. If you think yaml support is important I can try adding it later this month. Should we have two flags then, one for each, or what do you think?

can't parseFn parse file content by file name ext?

rasmus-kirk commented 6 months ago

If we add a wrapper function that reads the file extension and applies the correct parsing function accordingly, then yeah I think so. Should be cleaner.

trim21 commented 2 months ago

/ping