Skip to content

Commit

Permalink
updated documentation and commented code. overworked _get_system.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoEg committed Jun 23, 2024
1 parent b5dafff commit 9aa34d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added git remote repositories and directories as potential sources for config files in the cli.
* `title` and `description` can be set from `pretty` and `description` keys at root.
* Added default key for os systems.


### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Options are dynamically created with the schema part of the config file.
2. Add `pretty` and `description` keys.
3. Create lists like `key: Pretty Key`.
* `title` and `description` from within the schema overwrite `pretty` and `description` outside of the schema.
* For the package to set the default os to the running system, name the property `__os__`.

```yaml
schema:
Expand Down
16 changes: 12 additions & 4 deletions installation_instruction/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@
Repository: {__repository__}"""

def _get_system(option_types):
"""
Returns the os from the list of possible os systems defined in the schema.
:param option_types: list of system from the schema.
:type option_types: list
:return: os system from input list or None.
:rtype: string or None
"""

system = platform.system()
system_names = {
'Linux': 'lin',
'Linux': 'linux',
'Darwin': 'mac',
'Windows': 'win',
}

sub_default = system_names.get(system,None)
new_default = system_names.get(system,None)
for type in option_types:
default_type = type.lower()
if sub_default in default_type:
if new_default in type.lower():
return type

return None
Expand Down Expand Up @@ -95,6 +102,7 @@ def get_command(self, ctx, config_file: str) -> click.Command|None:
_red_echo("Error (parsing options from schema): " + str(e))
exit(1)

#set new default value for __os__ Option
for option in options:
if '__os__' in option.name:
system_default = _get_system(option.type.choices)
Expand Down

0 comments on commit 9aa34d8

Please sign in to comment.