Skip to content

Commit

Permalink
Add validate_str_list function and update dependencies schema
Browse files Browse the repository at this point in the history
This commit introduces the validate_str_list function to ensure that lists of strings are validated correctly. The function is then used to update the "depends_on" schema across multiple files for improved validation. Additionally, the version in pyproject.toml has been incremented from 0.3.1 to 0.3.2.
  • Loading branch information
trentonyo committed Aug 10, 2024
1 parent ba5a35c commit 1c68886
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "startout"
version = "0.3.1"
version = "0.3.2"
description = "Draft version of the StartOut CLI'"
authors = ["Trenton Yo <askstartout@gmail.com>", "Jake Gehrke <askstartout@gmail.com>"]
readme = "README.md"
Expand Down
5 changes: 3 additions & 2 deletions startout/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from schema import Schema, And, Or, Optional, Use

from startout.init_option import InitOption
from startout.util import replace_env, run_script_with_env_substitution, get_script, MonitorOutput, monitored_subprocess
from startout.util import replace_env, run_script_with_env_substitution, get_script, MonitorOutput, \
monitored_subprocess, validate_str_list


def check_for_key(name: str, key: str, scripts: dict):
Expand Down Expand Up @@ -89,7 +90,7 @@ class Module:
}
),
"scripts": module_scripts_schema,
Optional("depends_on"): Or(str, List[str]),
Optional("depends_on"): Or(str, validate_str_list),
Optional("init_options"): [module_init_options_schema]
}
)
Expand Down
4 changes: 2 additions & 2 deletions startout/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from schema import Schema, And, Or, Optional

from startout.util import run_script_with_env_substitution, get_script
from startout.util import run_script_with_env_substitution, get_script, validate_str_list


class Tool:
Expand Down Expand Up @@ -63,7 +63,7 @@ class Tool:
)
tool_schema = Schema(
{
Optional("depends_on"): Or(str, List[str]),
Optional("depends_on"): Or(str, validate_str_list),
"scripts": tool_scripts_schema
}
)
Expand Down
3 changes: 3 additions & 0 deletions startout/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self, title: str, subtitle: str, console: Console, log_path: Path):
self.log_path = log_path


def validate_str_list(value):
return isinstance(value, list) and all(isinstance(item, str) for item in value)

def bool_to_yn(bool_input: bool) -> str:
"""
Converts a boolean value to a 'y' or 'n' string representation.
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/starterfiles/starter2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ modules:
init: exit 0
destroy: exit 0
dependent_module:
depends_on: module
depends_on:
- module
dest: 2/equals/${ONE}
source:
script: exit 0
Expand Down

0 comments on commit 1c68886

Please sign in to comment.