Skip to content

Commit

Permalink
Add Command.add_args_iterable() and Command.add_args_mapping()
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisGaul committed May 25, 2024
1 parent e35c740 commit ac88990
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions python_on_whales/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Dict, Iterable, List, Literal, Optional, Union
from typing import Any, Dict, Iterable, List, Literal, Mapping, Optional, Union

import pydantic

from python_on_whales.download_binaries import (
download_docker_cli,
get_docker_binary_path_in_cache,
)
from python_on_whales.utils import to_list

from .utils import ValidPath, run
from . import utils
from .utils import ValidPath, run, to_list

CACHE_VALIDITY_PERIOD = 0.01

Expand All @@ -37,12 +37,23 @@ def add_flag(self, name: str, value: bool):
if value:
self.append(name)

def add_args_iterable(self, arg_name: str, values: Iterable[Any]):
for value in values:
self.extend([arg_name, value])

def add_args_iterable_or_single(
self, arg_name: str, iterable_or_single: Union[Iterable[Any], Any]
):
for value in to_list(iterable_or_single):
self.extend([arg_name, value])

def add_args_mapping(
self, arg_name: str, mapping: Mapping[Any, Any], *, separator="="
):
self.add_args_iterable(
arg_name, utils.format_mapping_for_cli(mapping, separator)
)

def __add__(self, other) -> "Command":
return Command(super().__add__(other))

Expand Down

0 comments on commit ac88990

Please sign in to comment.