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

Command argument refactoring proposition #31

Closed
leopoldhub opened this issue May 13, 2024 · 4 comments · Fixed by #66
Closed

Command argument refactoring proposition #31

leopoldhub opened this issue May 13, 2024 · 4 comments · Fixed by #66
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@leopoldhub
Copy link
Collaborator

leopoldhub commented May 13, 2024

Hi @TamtamHero ,

I would like to refactor the existing command line arguments, complete them with missing essential ones and would appreciate your feedback.

Here are the current arguments (including those in PR #29):

contexts:

  • direct : can be used in a command that will run the background service
  • indirect : can be used in a command that will communicate with the background service
option group context description
<strategy> run & configure direct & indirect the name of the strategy to use
--run run direct run the service
--config run direct specify the configuration path
--no-log run direct disable state logging
--list-strategies configure indirect print the available strategies
--query, -q configure indirect print the current strategy name
--reload, -r configure indirect reload the configuration file
--pause configure indirect temporarily disable the service
--resume configure indirect resume the service

And here are the new ones:

| option | group | context | description |
|---------------------------------------------------------------|-----------------|----------|------------------------------------------|
| --run (?<strategy>) | run | direct | run the service |
| --config | run | direct | specify the configuration path |
| --silent | run | direct | disable state logging |
| --use <strategy> | | indirect | run the service |
| --actual-strategy,-a | | indirect | print the current strategy name |
| --strategy-detail,-d (?<strategy>) | | indirect | list a strategy configuration |
| --list-strategies,--ls,-l | | indirect | print the available strategies |
| --reload-config,--reload, -r | | indirect | reload the configuration file |
| --add-strategy,-A <strategy-name> | add | indirect | add a new strategy to the config |
| --configure-strategy,-C <strategy-name> | configure | indirect | configure a strategy |
| --update-frequency,--uf,-u <update-freq> | add & configure | indirect | set the strategy update frequency |
| --moving-average-interval,--mai,-m <moving-average-interval> | add & configure | indirect | set the strategy moving average interval |
| --curve-point,--cp,-c <temp>:<fan-duty> | add & configure | indirect | set a point in the curve |
| --delete-strategy,-D <strategy-name> | | indirect | delete a strategy |
| --pause | | indirect | temporarily disable the service |
| --resume | | indirect | resume the service |

Edit: After much thoughts, I think we should use subcommands when possible, as they are more intuitive.

run : direct : run the service. (use reset to reset to the default strategy)

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies). (optional)
--config, -c config file path. (default: /etc/fw-fanctrl/config.json)
--silent, -s disable printing speed/temp status to stdout

reload : indirect : reload configuration

reset : indirect : reset the current strategy to the default one

set-default : indirect : set the default strategy

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies)
--discharge, --d is the default for discharging strategy

remove-default : indirect : remove the default strategy

argument description
--discharge, --d is the default for discharging strategy

add : indirect : add a new strategy

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies)
curve_point... a point in the temperature curve in the format: temp:speed
--update-frequency, --uf, -u time interval between every temperature update. (min: 1. default: 5)
--average-interval, --ai, -a number of seconds on which the moving average of temperature is computed. (min: 0. default: 20)

configure : indirect : configure an existing strategy

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies)
curve_point... a point in the temperature curve in the format: temp:speed. (optional)
--update-frequency, --uf, -u time interval between every temperature update. (min: 1. default: 5)
--average-interval, --ai, -a number of seconds on which the moving average of temperature is computed. (min: 0. default: 20)

delete : direct : delete an existing strategy

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies)

pause : direct : pause the service

resume : resume : pause the service

print : direct : print desired information

argument (OR) description
current-strategy print the current strategy
strategy-details strategy print the details of the specified strategy
strategies list the available strategies

The aim is to make them more intuitive and organised, and to achieve this many of them will have to be renamed/removed and users will have to change the way they use the actual commands.

What are your thoughts on this?
Should we go for it or add a deprecation warning for now?

@TamtamHero
Copy link
Owner

TamtamHero commented May 16, 2024

Hmmm I'm not convinced this would be a positive change.
Currently, we have quite a small program and --help gives all the info you need to use it. The args can be read and understood in seconds, since the feature set is minimal. Which is good, and expected for a program whose only job is to deal with fans and temperatures.
This would change with your proposal, with the addition of new niche arguments that won't be used by most people.
All the features added by these new commands can be achieved currently by editing manually the config file. I'd never use CLI to add a new curve (or to change anything that would affect the non-volatile state of the service, aka the config file), so I don't see how this could have a positive impact on user friendliness. I believe that opening a file and making some changes there before reloading a service is pretty typical and accepted.

Basically, I think we should respect these rules:

  • Non-volatile changes: config file
  • Volatile changes: command line

Other typical arguments against change applies too:

  • Don't fix what isn't broken
  • Don't change UX/break compatibility if you don't have to

Also, adding these would increase the line count. I feel like it's a nice feature that the script is small, so people can have a look before giving it sudo rights. Anything increasing the size of the script must have serious arguments going for it.

@leopoldhub
Copy link
Collaborator Author

Yes, I understand
I plan to add (or create a separate project?) a simple GUI for fan management using this project, hence my suggestion for rule management, but using the config.json for permanent changes is fine too.

The current command line arguments have some problems too, eg. we can ask to reload, change strategy, query current strategy and print the strategy list at the same time.

Refactoring them using subcommands allows us to restrict the user to one and only one command at a time.

With this in mind, we could continue to support the old arguments (without generating help for them, forcing new users to use new ones) and add the new format.

run : direct : run the service. (use reset to reset to the default strategy)

argument description
strategy name of the strategy to use e.g: "lazy". (use print strategies to list available strategies). (optional)
--config, -c config file path. (default: /etc/fw-fanctrl/config.json)
--silent, -s disable printing speed/temp status to stdout

reload : indirect : reload configuration

reset : indirect : reset the current strategy to the default one

pause : direct : pause the service

resume : resume : pause the service

print : direct : print desired information

argument (OR) description
current-strategy print the current strategy
strategy-details strategy print the details of the specified strategy
strategies list the available strategies

as for the line count, I plan to separate the script into several well named files/modules to improve readability.

@TamtamHero
Copy link
Owner

TamtamHero commented May 17, 2024

I see. It's a bit of a dilemma for me, on one hand I like that this project fits in a single script. On the other hand, you're there, willing to increase the feature set and to commit some good work, at the price of adding complexity and breaking a few things.
I'm a strong partisan of "better is the enemy of good", but also I don't want to discourage you.
So, all things measured, if you're wiling to work on this, please do.
The GUI might live in a different repo, but it would be better that it uses fw-fanctrl under the hood rather than tweaking directly its config file (which means you can add back the arguments about adding/removing a curve)

I invited you on this repo btw, so as to give you collaborator permissions (let me know if you don't want them)

@leopoldhub
Copy link
Collaborator Author

I will think a bit more about the file splitting but I keep thinking that separating them would make the project easier to maintain, we will see.

I will also do my best not to break current systems and keep previous arguments as a backup for a while when adding the new ones.

Thank you for your trust in me, feel free to revoke these permissions if you ever need/want to.

@leopoldhub leopoldhub self-assigned this May 21, 2024
@leopoldhub leopoldhub added enhancement New feature or request question Further information is requested labels May 21, 2024
leopoldhub added a commit to leopoldhub/fw-fanctrl that referenced this issue Aug 11, 2024
the old argument format is deprecated but still usable.

improved feedback when executing commands.

TamtamHero#31
@leopoldhub leopoldhub linked a pull request Aug 11, 2024 that will close this issue
leopoldhub added a commit that referenced this issue Aug 13, 2024
* forcing utf-8 encoding for socket messages and usage of stopServerSocket method instead of manual closing, as well as updating error detection pattern

* README.md documentation update

* change log format on fatal crash

* fix badges links

* adding windows platform badge and issue template

* fix `:` instead of `=`

* first part of the command argument refactoring.

the old argument format is deprecated but still usable.

improved feedback when executing commands.

#31

* trim blank lines in README.md
leopoldhub added a commit that referenced this issue Aug 25, 2024
* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <nina-git@klama.name>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* Clarify behaviour on service stop or pause (#53) (#55)

* Separating FanController into different subclasses to allow HardwareController and SocketController diversity. 2 (Repost of #50) (#58)

* separating `FanController` into different subclasses to allow `HardwareController` and `SocketController` diversity

* adding the new arguments into the README.md

* fixing an indentation error causing `--strategy <strategy>` not to work (the simple `<strategy>` still worked)

* fixing missing print for command execution (#63)

* forcing utf-8 encoding for socket messages and usage of stopServerSocket method instead of manual closing, as well as updating error detection pattern (#64)

* README.md documentation update (#65)

* forcing utf-8 encoding for socket messages and usage of stopServerSocket method instead of manual closing, as well as updating error detection pattern

* README.md documentation update

* change log format on fatal crash

* fix badges links

* adding windows platform badge and issue template

* fix `:` instead of `=`

* disabling part of the README.md while waiting for merge

* Command arguments refactoring Pt.1 (#66)

* forcing utf-8 encoding for socket messages and usage of stopServerSocket method instead of manual closing, as well as updating error detection pattern

* README.md documentation update

* change log format on fatal crash

* fix badges links

* adding windows platform badge and issue template

* fix `:` instead of `=`

* first part of the command argument refactoring.

the old argument format is deprecated but still usable.

improved feedback when executing commands.

#31

* trim blank lines in README.md

* finishing touches (#67)

* add no battery mode for mainboards without battery (#69)

* add configuration for no battery mode in hardware controller

* fix wrong line getting noBatteryMode

* dynamically fetching battery sensor on init/reload

* add --no-battery flag for install

* update readme with --no-battery flag

* rework no battery config to come from service args

* change sensors to be ectool specific

- reword the argument to be more clear about battery sensors
- move `noBatteryMode` and `nonBatterySensors` to EctoolHardwareController
- update `getNonBatterySensors` to be able to handle more than one sensor
- update installer and readme accordingly

* update grep command for checking existing `--no-battery-sensors`

* combine getTemperature functions to one

* add documentation for run option `--no-battery-sensors`

* rename variable `NO_BATTERY` to `NO_BATTERY_SENSOR`

* update the installer to use existing placeholder format

* rename noBatterySensorMode variables and functions for clarity

* rename placeholder to `NO_BATTERY_SENSOR_OPTION` for clarity

* update comments in installer to reflect new argument name

* adding ectool sub-dependency to documentation (#70)

* typo "tempurature" => "temperature" (#71)

typo "tempurature" => "temperature"

* typo "tempurature" => "temperature" (#72)

typo "tempurature" => "temperature"

* Add ToC + link to NixOS Documentation (#75)

* add doc folder

* update nix link

* add toc

* add link

* add missin #

* add doc

* fix link

* add new line under titles

* add --no-sudo option (#76)

* Add choice to print fan speed percentage (#78)

* Add option to print current speed percentage

* Update README.md

* Update commands.md

* Add print choice descriptions to help text

* add missing no_sudo check (#79)

* Add NixOS Flake (#26)

* initial

* update gitignore

* update inputs

* add fw-ectool dependencie

* add module

* fix tabs

* fix package

* fix typo

* fix service

* fix type

* add options

* fix service

* fix build inputs

* add Readme + add suspend script

* remove unneeded };

* fix pkgs.writeShellScript

* remvoe \

* try

* add self

* fix module

* update package

* fix package

* use sleep script

* add config options

* fix typo

* fix typo

* add defaults

* fix type

* add prettyier

* remove beautifyer

* udpate readme

* update installer script

* add missing path

* Update README.md

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update flake.nix

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update nix/module.nix

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* add descriptions

* fix uninstall

* update readme

* add description

* remove requiremetns.txt + add github actions

* update action

* rename workflow test

* fix service

* try

* try

* Update README.md

* Update README.md

* chagne flake description

* fix suspend script

* fix script

* fix path

* fix install.sh

* fix --no-sudo

* add --no-sudo to other scripts

* fix check

* add option check

* add missing "

* Rename nix action

---------

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update branch to main branch (#54)

* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <nina-git@klama.name>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* use ectool form nixpkgs

* update flake

* remove old deps

* remove duplicated pkgs

---------

Co-authored-by: Léopold Hubert <hubertleopold01@gmail.com>
Co-authored-by: Nina Alexandra Klama <github@fklama.de>
Co-authored-by: DeflateAwning <11021263+DeflateAwning@users.noreply.github.com>

* Update to main branch + switch to fw-ectool (#61)

* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <nina-git@klama.name>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* Clarify behaviour on service stop or pause (#53) (#55)

* Separating FanController into different subclasses to allow HardwareController and SocketController diversity. 2 (Repost of #50) (#58)

* separating `FanController` into different subclasses to allow `HardwareController` and `SocketController` diversity

* adding the new arguments into the README.md

* fixing an indentation error causing `--strategy <strategy>` not to work (the simple `<strategy>` still worked)

* add fw-ectool in module

* fixing missing print for command execution (#63)

---------

Co-authored-by: Léopold Hubert <hubertleopold01@gmail.com>
Co-authored-by: Nina Alexandra Klama <github@fklama.de>
Co-authored-by: DeflateAwning <11021263+DeflateAwning@users.noreply.github.com>

* add doc + .gitignore

* Add NixOS Flake (#26)

* initial

* update gitignore

* update inputs

* add fw-ectool dependencie

* add module

* fix tabs

* fix package

* fix typo

* fix service

* fix type

* add options

* fix service

* fix build inputs

* add Readme + add suspend script

* remove unneeded };

* fix pkgs.writeShellScript

* remvoe \

* try

* add self

* fix module

* update package

* fix package

* use sleep script

* add config options

* fix typo

* fix typo

* add defaults

* fix type

* add prettyier

* remove beautifyer

* udpate readme

* update installer script

* add missing path

* Update README.md

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update flake.nix

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update nix/module.nix

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* add descriptions

* fix uninstall

* update readme

* add description

* remove requiremetns.txt + add github actions

* update action

* rename workflow test

* fix service

* try

* try

* Update README.md

* Update README.md

* chagne flake description

* fix suspend script

* fix script

* fix path

* fix install.sh

* fix --no-sudo

* add --no-sudo to other scripts

* fix check

* add option check

* add missing "

* Rename nix action

---------

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

* Update branch to main branch (#54)

* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <nina-git@klama.name>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* use ectool form nixpkgs

* update flake

* remove old deps

* remove duplicated pkgs

---------

Co-authored-by: Léopold Hubert <hubertleopold01@gmail.com>
Co-authored-by: Nina Alexandra Klama <github@fklama.de>
Co-authored-by: DeflateAwning <11021263+DeflateAwning@users.noreply.github.com>

* Update to main branch + switch to fw-ectool (#61)

* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <nina-git@klama.name>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* Clarify behaviour on service stop or pause (#53) (#55)

* Separating FanController into different subclasses to allow HardwareController and SocketController diversity. 2 (Repost of #50) (#58)

* separating `FanController` into different subclasses to allow `HardwareController` and `SocketController` diversity

* adding the new arguments into the README.md

* fixing an indentation error causing `--strategy <strategy>` not to work (the simple `<strategy>` still worked)

* add fw-ectool in module

* fixing missing print for command execution (#63)

---------

Co-authored-by: Léopold Hubert <hubertleopold01@gmail.com>
Co-authored-by: Nina Alexandra Klama <github@fklama.de>
Co-authored-by: DeflateAwning <11021263+DeflateAwning@users.noreply.github.com>

---------

Co-authored-by: Léopold Hubert <hubertleopold01@gmail.com>
Co-authored-by: Nina Alexandra Klama <github@fklama.de>
Co-authored-by: DeflateAwning <11021263+DeflateAwning@users.noreply.github.com>
Co-authored-by: Oli Thornton <50975890+saizo80@users.noreply.github.com>
Co-authored-by: Ryan <speenah@pm.me>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants