pashi icon indicating copy to clipboard operation
pashi copied to clipboard

Add command line option to set & view default options

Open delphidabbler opened this issue 4 years ago • 9 comments

At present the only way to configure PasHi is to create a file named config in PasHi's data directory at %APPDATA%\DelphiDabbler\PasHi.

It would be useful to be able to write configuration information to the config file from the command line.

A command line option could be added to do this that is similar to git config: something like pashi --options.

For example

  • --options set command=param or --options set command would write the given command to the config file, with any required parameter. Setting the same option twice would replace any parameter in the config file. For a parameter-less option this would be a no-op.
  • --options check command would indicate if a command was present in the config file or not. For a command with a parameter the parameter would be displayed.
  • --options show would display all current options in the config file.
  • --options delete command would remove the given command from the config file. An error would be reported if the command wasn't present.
  • --options purge would remove all options from the config file (or delete the file).

It would be useful if commands being set could be validated.

The command should also prevent any blacklisted commands from being written to the config file. Blacklisted commands (i.e. those that aren't valid in the config file) should be help and options.

delphidabbler avatar Sep 16 '21 00:09 delphidabbler

Could also add --options edit to display config file in a text editor.

delphidabbler avatar Sep 16 '21 12:09 delphidabbler

Considering using --config rather than --options as main command.

Another possibility is to use several related commands to reduce number of parameters. Thus:

Original command Alternative command
--options set command=param --config-set command=param
--options set command --config-set command
--options check command --config-find command
--options show --config-show
--options delete command --config-delete command
--options purge --config-purge
--options edit --config-edit

May need to experiment with both approaches.

delphidabbler avatar Sep 18 '21 19:09 delphidabbler

Probably adding this to v3 now.

delphidabbler avatar Sep 19 '21 15:09 delphidabbler

Further discussion of this and other v3 development ideas to continue in the v3 Development Project

delphidabbler avatar Sep 20 '21 03:09 delphidabbler

Consider issue #23 before starting work on this.

delphidabbler avatar Oct 09 '21 10:10 delphidabbler

Further discussion of this and other v3 development ideas to continue in the v3 Development Project

The project noted above simply references the v3-design document on Google Drive, which can't be edited. So I've copied what it says below.


Configuration Execution Context

This context is used to update the program's config file and to display both all and current settings.

Activated by the --config command being the first entry on the command line.

Requires access to the command parser to check validity of the name of any command and it's parameter that is requested to be written to the config file.

The command takes one of the following forms:

  1. --config
  2. --config view
  3. --config status <command>
  4. --config set <command> <parameters>
  5. --config delete <command>
  6. --config clear
  7. --config clear force

[where] <command> must be the name of a valid config file command [and] <parameters> must be zero or more space separated parameters that are valid for <command>

The purpose of the different --config command forms is:

  1. Displays brief help on using the command
  2. Displays a sorted list of all commands in the config file along with any associated parameters
  3. Checks whether <command> is in the config file and displays its parameters, if any.
  4. Writes <command> and any given <parameters> to the config file.
  5. Deletes <command> from the config file.
  6. Clears the contents of the config file. Prompts for confirmation.
  7. Clears the contents of the config file without prompting for permission.

Notice that --options has changed to --config and that the idea of multiple commands with different names has been dropped.

Further discussion will take the content of this comment as a starting point.

delphidabbler avatar Oct 23 '22 06:10 delphidabbler

Consider issue #23 before starting work on this.

Instead of having a separate --use-config-file option --config could be extended to have a use sub-command that sets the config file to use:

  • --config use <filename> to set or create the config file to use in all further calls to --config.
  • --config use - to restore the default config file.

This command would adopt the suggestion in issue #23 to record the current config file name in a file stored in a special (hidden?) .pashi directory. Users will be forbidden from using this directory for custom config or any custom CSS files.

delphidabbler avatar Oct 23 '22 06:10 delphidabbler

Consider issue #23 before starting work on this.

Instead of having a separate --use-config-file option --config could be extended to have a use sub-command

Adopting this suggestion means that issue #23 can be closed and wrapped into this issue.

delphidabbler avatar Oct 23 '22 06:10 delphidabbler

To summarise, the single command --config will be used, with the following parameters:

Parameter Description
view or list Displays a sorted list of all the command's in the config file.
status <command> Checks whether <command> is in the config file and displays its parameters, if any.
set <command> <parameters> Writes <command> and any given <parameters> to the config file.
delete <command> Deletes <command> from the config file.
clear [force] Clears the contents of the config file. Prompts for confirmation, unless the optional force flag is present.
copy <filename> [force] Copy content of current config file to <filename>, prompting for confirmation if <filename> exists, unless the optional force flag is present.
copy - [force] Copy content of current config file to default config file, prompting for confirmation if default config file exists, unless the optional force flag is present.
use <filename> Set or create the config file <filename> to be used in all further calls to --config.
use - Restore the default config file for use in all further calls to --config.
none or help Displays brief help on using the command.

The current config file to use would be recorded in file named config-use in the %AppData%\DelphiDabbler\PasHi\.pashi directory. If this file is missing the default config file is used.

User config files are stored in %AppData%\DelphiDabbler\PasHi\.pashi\user-cfg\ directory, whereas the default config file is stored in %AppData%\DelphiDabbler\PasHi\.pashi\default-cfg file.

delphidabbler avatar May 28 '23 17:05 delphidabbler