falyx 0.1.57__py3-none-any.whl → 0.1.58__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,9 +36,11 @@ class SaveFileAction(BaseAction):
36
36
  file_path: str,
37
37
  file_type: FileType | str = FileType.TEXT,
38
38
  mode: Literal["w", "a"] = "w",
39
- inject_last_result: bool = True,
40
- inject_into: str = "data",
39
+ data: Any = None,
41
40
  overwrite: bool = True,
41
+ create_dirs: bool = True,
42
+ inject_last_result: bool = False,
43
+ inject_into: str = "data",
42
44
  ):
43
45
  """
44
46
  SaveFileAction allows saving data to a file.
@@ -47,17 +49,22 @@ class SaveFileAction(BaseAction):
47
49
  name (str): Name of the action.
48
50
  file_path (str | Path): Path to the file where data will be saved.
49
51
  file_type (FileType | str): Format to write to (e.g. TEXT, JSON, YAML).
52
+ mode (Literal["w", "a"]): File mode (default: "w").
53
+ data (Any): Data to be saved (if not using inject_last_result).
54
+ overwrite (bool): Whether to overwrite the file if it exists.
55
+ create_dirs (bool): Whether to create parent directories if they do not exist.
50
56
  inject_last_result (bool): Whether to inject result from previous action.
51
57
  inject_into (str): Kwarg name to inject the last result as.
52
- overwrite (bool): Whether to overwrite the file if it exists.
53
58
  """
54
59
  super().__init__(
55
60
  name=name, inject_last_result=inject_last_result, inject_into=inject_into
56
61
  )
57
62
  self._file_path = self._coerce_file_path(file_path)
58
63
  self._file_type = self._coerce_file_type(file_type)
64
+ self.data = data
59
65
  self.overwrite = overwrite
60
66
  self.mode = mode
67
+ self.create_dirs = create_dirs
61
68
 
62
69
  @property
63
70
  def file_path(self) -> Path | None:
@@ -126,6 +133,14 @@ class SaveFileAction(BaseAction):
126
133
  elif self.file_path.exists() and not self.overwrite:
127
134
  raise FileExistsError(f"File already exists: {self.file_path}")
128
135
 
136
+ if self.file_path.parent and not self.file_path.parent.exists():
137
+ if self.create_dirs:
138
+ self.file_path.parent.mkdir(parents=True, exist_ok=True)
139
+ else:
140
+ raise FileNotFoundError(
141
+ f"Directory does not exist: {self.file_path.parent}"
142
+ )
143
+
129
144
  try:
130
145
  if self.file_type == FileType.TEXT:
131
146
  self.file_path.write_text(data, encoding="UTF-8")
@@ -175,7 +190,7 @@ class SaveFileAction(BaseAction):
175
190
 
176
191
  async def _run(self, *args, **kwargs):
177
192
  combined_kwargs = self._maybe_inject_last_result(kwargs)
178
- data = combined_kwargs.get(self.inject_into)
193
+ data = self.data or combined_kwargs.get(self.inject_into)
179
194
 
180
195
  context = ExecutionContext(
181
196
  name=self.name, args=args, kwargs=combined_kwargs, action=self
falyx/parser/argument.py CHANGED
@@ -9,22 +9,37 @@ from falyx.parser.argument_action import ArgumentAction
9
9
 
10
10
  @dataclass
11
11
  class Argument:
12
- """Represents a command-line argument."""
12
+ """
13
+ Represents a command-line argument.
14
+
15
+ Attributes:
16
+ flags (tuple[str, ...]): Short and long flags for the argument.
17
+ dest (str): The destination name for the argument.
18
+ action (ArgumentAction): The action to be taken when the argument is encountered.
19
+ type (Any): The type of the argument (e.g., str, int, float) or a callable that converts the argument value.
20
+ default (Any): The default value if the argument is not provided.
21
+ choices (list[str] | None): A list of valid choices for the argument.
22
+ required (bool): True if the argument is required, False otherwise.
23
+ help (str): Help text for the argument.
24
+ nargs (int | str | None): Number of arguments expected. Can be an int, '?', '*', '+', or None.
25
+ positional (bool): True if the argument is positional (no leading - or -- in flags), False otherwise.
26
+ resolver (BaseAction | None):
27
+ An action object that resolves the argument, if applicable.
28
+ lazy_resolver (bool): True if the resolver should be called lazily, False otherwise
29
+ """
13
30
 
14
31
  flags: tuple[str, ...]
15
- dest: str # Destination name for the argument
16
- action: ArgumentAction = (
17
- ArgumentAction.STORE
18
- ) # Action to be taken when the argument is encountered
19
- type: Any = str # Type of the argument (e.g., str, int, float) or callable
20
- default: Any = None # Default value if the argument is not provided
21
- choices: list[str] | None = None # List of valid choices for the argument
22
- required: bool = False # True if the argument is required
23
- help: str = "" # Help text for the argument
24
- nargs: int | str | None = None # int, '?', '*', '+', None
25
- positional: bool = False # True if no leading - or -- in flags
26
- resolver: BaseAction | None = None # Action object for the argument
27
- lazy_resolver: bool = False # True if resolver should be called lazily
32
+ dest: str
33
+ action: ArgumentAction = ArgumentAction.STORE
34
+ type: Any = str
35
+ default: Any = None
36
+ choices: list[str] | None = None
37
+ required: bool = False
38
+ help: str = ""
39
+ nargs: int | str | None = None
40
+ positional: bool = False
41
+ resolver: BaseAction | None = None
42
+ lazy_resolver: bool = False
28
43
 
29
44
  def get_positional_text(self) -> str:
30
45
  """Get the positional text for the argument."""
falyx/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.57"
1
+ __version__ = "0.1.58"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: falyx
3
- Version: 0.1.57
3
+ Version: 0.1.58
4
4
  Summary: Reliable and introspectable async CLI action framework.
5
5
  License: MIT
6
6
  Author: Roland Thomas Jr
@@ -20,7 +20,7 @@ falyx/action/menu_action.py,sha256=UwMF3Y3v8AWXGCkVpzj_k3pCge5BlJvKhqGYXh_dNCc,5
20
20
  falyx/action/process_action.py,sha256=nUNcJD6Ms34vmj8njWzv1R1P9xJTyJmelnyJksHcp7M,4666
21
21
  falyx/action/process_pool_action.py,sha256=XeL6e7vsy4OkOWGQHD0ET14CzuyJ0TL-c1W5VIgdCP8,6204
22
22
  falyx/action/prompt_menu_action.py,sha256=PTn6US8ql5SU7ilEMVCeoGqKTc31be3AbdCfcrZ6ujU,5034
23
- falyx/action/save_file_action.py,sha256=P5gfTUFnmzAK8yJSd4b5GV69G58MxJXgb4H7kXiRteA,9200
23
+ falyx/action/save_file_action.py,sha256=Pe_j0hZjDNsO14bykzVYM0gkWB3zmpB1cExSN01IQOI,9899
24
24
  falyx/action/select_file_action.py,sha256=PcV22_wiPeDoJLIhHRiEUmW8N3pYeqQZMVTscQKXuas,9867
25
25
  falyx/action/selection_action.py,sha256=L1evMm7oAQFGMviZ8nMwFKhWKWe8X7wW6dJPHGxpqAE,15398
26
26
  falyx/action/shell_action.py,sha256=0A_kvZLsYmeLHInMM_4Jpe8GCSnXzGBm7H9PnXPvbAs,4055
@@ -45,7 +45,7 @@ falyx/menu.py,sha256=9kvLZhkC8PoSQvv1NZQsPIFSDy11dXfFgqVAuDmtfsM,3752
45
45
  falyx/options_manager.py,sha256=dFAnQw543tQ6Xupvh1PwBrhiSWlSACHw8K-sHP_lUh4,2842
46
46
  falyx/parser/.pytyped,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  falyx/parser/__init__.py,sha256=NbxAovKIY-duFTs6DAsdM_OzL7s3VIu19KMOmltX9ts,512
48
- falyx/parser/argument.py,sha256=piY3edF9rdUtOP343TWTyOq3OuNJWyQA6K9CFy2mrvY,3519
48
+ falyx/parser/argument.py,sha256=MIKUj-hrdLDUK8xuW84_l9ms_t5CoNFpVDmxMZIbW-I,4105
49
49
  falyx/parser/argument_action.py,sha256=rNVeth0eMpkZRU_eT1RPVxOGzD4pbdAMx9Kq07T4mG4,709
50
50
  falyx/parser/command_argument_parser.py,sha256=Ej4gYOxSUOYfLr5b0KkZkC0OkuSUrj54JpuI0D0C6h4,37504
51
51
  falyx/parser/parsers.py,sha256=X3eEltxBbwRwWG5Q1A1GqSdQCJZAYN5Eub0_U6dlBN4,9159
@@ -62,9 +62,9 @@ falyx/themes/__init__.py,sha256=1CZhEUCin9cUk8IGYBUFkVvdHRNNJBEFXccHwpUKZCA,284
62
62
  falyx/themes/colors.py,sha256=4aaeAHJetmeNInI0Zytg4E3YqKfPFelpf04vtjSvsS8,19776
63
63
  falyx/utils.py,sha256=U45xnZFUdoFC4xiji_9S1jHS5V7MvxSDtufP8EgB0SM,6732
64
64
  falyx/validators.py,sha256=DHq-ELpeYVHvRg9daY4Te6ufAf4ryUAM7i_uF7B15Sc,5919
65
- falyx/version.py,sha256=4_3hAGEogvYbOy6vn6QDJpHwwyZfPSVQHAgrUMAMbLI,23
66
- falyx-0.1.57.dist-info/LICENSE,sha256=B0yqgaHuSdhN7T3OBmgQSiDTy8HqT5Oe_dLypRe4Ra4,1073
67
- falyx-0.1.57.dist-info/METADATA,sha256=RREKc2TcwfK9cxUsOnVpqHjovgIDIIZwz1i8jzcXtJk,5561
68
- falyx-0.1.57.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
69
- falyx-0.1.57.dist-info/entry_points.txt,sha256=j8owOSl2j1Ss8DtGMnKfgehKaolqnIPhVFHaUBLUnMs,45
70
- falyx-0.1.57.dist-info/RECORD,,
65
+ falyx/version.py,sha256=ujgZXX_cw13M2UkyXWVg5j1fgdE25Qb3rUzLZVokSKg,23
66
+ falyx-0.1.58.dist-info/LICENSE,sha256=B0yqgaHuSdhN7T3OBmgQSiDTy8HqT5Oe_dLypRe4Ra4,1073
67
+ falyx-0.1.58.dist-info/METADATA,sha256=Kz5boaWHPPVBRUvQEJFrOOnQZdwUcGGTnwwQ5lsTaTg,5561
68
+ falyx-0.1.58.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
69
+ falyx-0.1.58.dist-info/entry_points.txt,sha256=j8owOSl2j1Ss8DtGMnKfgehKaolqnIPhVFHaUBLUnMs,45
70
+ falyx-0.1.58.dist-info/RECORD,,
File without changes