Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Improve default argument handling #916

Merged
merged 97 commits into from
Mar 7, 2024
Merged

Improve default argument handling #916

merged 97 commits into from
Mar 7, 2024

Conversation

nwatson22
Copy link
Member

@nwatson22 nwatson22 commented Feb 24, 2024

Closes #885.

Overhauls the way command line argument parsing and parameter passing is done.
When building a pyk-based command-line tool, for each subcommand of the tool, extend class Command . This subclass should contain all information about what arguments are accepted by that command (through providing its own arguments or inheriting from other Options classes), the default values of those arguments, the name of the command, and the help string for the command, as static fields. The values of those options for a specific invocation of that command are stored as non-static fields of a Command. The Command subclass contains the code that runs when that command is called in exec(). In addition, default values of arguments inherited from other Options classes can be overridden in the subclass.

The CLI class manages the tool's CLI options. It is constructed by passing in the name of every command subclass to be included in the tool. It can then build the whole ArgumentParser for the tool and process the arguments to instantiate a new *Command of the correct type and with the correct arguments.

Advantages:

  • All information about a subcommand is consolidated into one place
  • Default values specified in only one place
  • Commands only have to be listed once, when instantiating CLI
  • Setting up an argument parser with all subcommands is done automatically.
  • Routing of requested command to its associated execution function is done automatically.

@nwatson22 nwatson22 self-assigned this Feb 24, 2024
src/pyk/cli/args.py Outdated Show resolved Hide resolved
src/pyk/cli/args.py Outdated Show resolved Hide resolved
@ehildenb
Copy link
Member

ehildenb commented Mar 7, 2024

Going to merge this, and get it pushed through to all downstream repos, then can work on next batch of refactorings. Mostly because I have other CLI changes that I want to go through, and want ot try out the new interface for making those changes.

After we get this pushed through, we can discuss the next refactoring/design that we'd like to pursue here: runtimeverification/k#4188

@rv-jenkins rv-jenkins merged commit 0eb8d49 into master Mar 7, 2024
12 checks passed
@rv-jenkins rv-jenkins deleted the noah/default-options branch March 7, 2024 18:27
ehildenb added a commit that referenced this pull request Mar 8, 2024
rv-jenkins pushed a commit that referenced this pull request Mar 8, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- #955
- #916

---------

Co-authored-by: devops <[email protected]>
@nwatson22 nwatson22 restored the noah/default-options branch March 8, 2024 18:19
ehildenb pushed a commit that referenced this pull request Mar 11, 2024
Changes from:
- #916
- #955

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- runtimeverification/pyk#955
- runtimeverification/pyk#916

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Changes from:
- runtimeverification/pyk#916
- runtimeverification/pyk#955

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Closes runtimeverification/pyk#885.

Overhauls the way command line argument parsing and parameter passing is
done.
When building a pyk-based command-line tool, for each subcommand of the
tool, extend `class Command` . This subclass should contain all
information about what arguments are accepted by that command (through
providing its own arguments or inheriting from other `Options` classes),
the default values of those arguments, the name of the command, and the
help string for the command, as static fields. The values of those
options for a specific invocation of that command are stored as
non-static fields of a `Command`. The `Command` subclass contains the
code that runs when that command is called in `exec()`. In addition,
default values of arguments inherited from other `Options` classes can
be overridden in the subclass.

The `CLI` class manages the tool's CLI options. It is constructed by
passing in the name of every command subclass to be included in the
tool. It can then build the whole `ArgumentParser` for the tool and
process the arguments to instantiate a new `*Command` of the correct
type and with the correct arguments.

Advantages:
- All information about a subcommand is consolidated into one place
- Default values specified in only one place
- Commands only have to be listed once, when instantiating `CLI`
- Setting up an argument parser with all subcommands is done
automatically.
- Routing of requested command to its associated execution function is
done automatically.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- runtimeverification/pyk#955
- runtimeverification/pyk#916

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Closes runtimeverification/pyk#885.

Overhauls the way command line argument parsing and parameter passing is
done.
When building a pyk-based command-line tool, for each subcommand of the
tool, extend `class Command` . This subclass should contain all
information about what arguments are accepted by that command (through
providing its own arguments or inheriting from other `Options` classes),
the default values of those arguments, the name of the command, and the
help string for the command, as static fields. The values of those
options for a specific invocation of that command are stored as
non-static fields of a `Command`. The `Command` subclass contains the
code that runs when that command is called in `exec()`. In addition,
default values of arguments inherited from other `Options` classes can
be overridden in the subclass.

The `CLI` class manages the tool's CLI options. It is constructed by
passing in the name of every command subclass to be included in the
tool. It can then build the whole `ArgumentParser` for the tool and
process the arguments to instantiate a new `*Command` of the correct
type and with the correct arguments.

Advantages:
- All information about a subcommand is consolidated into one place
- Default values specified in only one place
- Commands only have to be listed once, when instantiating `CLI`
- Setting up an argument parser with all subcommands is done
automatically.
- Routing of requested command to its associated execution function is
done automatically.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- runtimeverification/pyk#955
- runtimeverification/pyk#916

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Closes runtimeverification/pyk#885.

Overhauls the way command line argument parsing and parameter passing is
done.
When building a pyk-based command-line tool, for each subcommand of the
tool, extend `class Command` . This subclass should contain all
information about what arguments are accepted by that command (through
providing its own arguments or inheriting from other `Options` classes),
the default values of those arguments, the name of the command, and the
help string for the command, as static fields. The values of those
options for a specific invocation of that command are stored as
non-static fields of a `Command`. The `Command` subclass contains the
code that runs when that command is called in `exec()`. In addition,
default values of arguments inherited from other `Options` classes can
be overridden in the subclass.

The `CLI` class manages the tool's CLI options. It is constructed by
passing in the name of every command subclass to be included in the
tool. It can then build the whole `ArgumentParser` for the tool and
process the arguments to instantiate a new `*Command` of the correct
type and with the correct arguments.

Advantages:
- All information about a subcommand is consolidated into one place
- Default values specified in only one place
- Commands only have to be listed once, when instantiating `CLI`
- Setting up an argument parser with all subcommands is done
automatically.
- Routing of requested command to its associated execution function is
done automatically.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- runtimeverification/pyk#955
- runtimeverification/pyk#916

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Closes runtimeverification/pyk#885.

Overhauls the way command line argument parsing and parameter passing is
done.
When building a pyk-based command-line tool, for each subcommand of the
tool, extend `class Command` . This subclass should contain all
information about what arguments are accepted by that command (through
providing its own arguments or inheriting from other `Options` classes),
the default values of those arguments, the name of the command, and the
help string for the command, as static fields. The values of those
options for a specific invocation of that command are stored as
non-static fields of a `Command`. The `Command` subclass contains the
code that runs when that command is called in `exec()`. In addition,
default values of arguments inherited from other `Options` classes can
be overridden in the subclass.

The `CLI` class manages the tool's CLI options. It is constructed by
passing in the name of every command subclass to be included in the
tool. It can then build the whole `ArgumentParser` for the tool and
process the arguments to instantiate a new `*Command` of the correct
type and with the correct arguments.

Advantages:
- All information about a subcommand is consolidated into one place
- Default values specified in only one place
- Commands only have to be listed once, when instantiating `CLI`
- Setting up an argument parser with all subcommands is done
automatically.
- Routing of requested command to its associated execution function is
done automatically.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Tamás Tóth <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Two changes to options are reverted, which weren't able to be pushed
through KEVM:

- runtimeverification/pyk#955
- runtimeverification/pyk#916

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve handling of command line options
4 participants