Skip to content

Commit

Permalink
refactor: deprecate inspect and download feature commands
Browse files Browse the repository at this point in the history
changed command structure and hierarchy
  • Loading branch information
danielbraun89 committed Mar 17, 2023
1 parent 96d4f22 commit 82ed823
Show file tree
Hide file tree
Showing 31 changed files with 250 additions and 272 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Feature Generation:

```
Usage: python -m dcontainer feature generate [OPTIONS]
Usage: python -m dcontainer generate devcontainer-feature [OPTIONS]
FEATURE_DEFINITION
OUTPUT_DIR
Expand Down Expand Up @@ -73,7 +73,7 @@ This is an *extended* version of the [devcontainer-feature.json](https://contain
"version": {
"type": "string",
"default": "latest",
"description": "Select the version of act to install."
"description": "Select the version of act to install2."
}
},

Expand Down Expand Up @@ -103,5 +103,5 @@ git clone https://github.com/devcontainers-contrib/cli --depth 1
cd cli


dcontainer feature generate "./test/resources/test_feature_definitions/elixir-asdf/feature-definition.json" "./output_dir"
dcontainer generate devcontainer-feature "./test/resources/test_feature_definitions/elixir-asdf/feature-definition.json" "./output_dir"
```
6 changes: 4 additions & 2 deletions dcontainer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import typer

from dcontainer.cli.feature import app as feature_app
from dcontainer.cli.install import app as install_app
from dcontainer.cli.generate import app as generate_app
from dcontainer.utils.version import (
resolve_own_package_version,
resolve_own_release_version,
)

app = typer.Typer(pretty_exceptions_show_locals=False, pretty_exceptions_short=False)
app.add_typer(feature_app, name="feature")
app.add_typer(install_app, name="install")
app.add_typer(generate_app, name="generate")


def version_callback(value: bool) -> None:
Expand Down
12 changes: 0 additions & 12 deletions dcontainer/cli/download/download_feature.py

This file was deleted.

100 changes: 0 additions & 100 deletions dcontainer/cli/feature.py

This file was deleted.

33 changes: 33 additions & 0 deletions dcontainer/cli/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging
import pathlib
from typing import Optional

import typer


logger = logging.getLogger(__name__)

app = typer.Typer(pretty_exceptions_show_locals=False, pretty_exceptions_short=False)

app.command()


@app.command("devcontainer-feature")
def generate_command(
feature_definition: pathlib.Path,
output_dir: pathlib.Path,
release_version: Optional[str] = None
) -> None:
try:
from dcontainer.devcontainer.feature_generation.oci_feature_generator import OCIFeatureGenerator
except ImportError as e:
logger.error(
"Some imports required for feature generation are missing.\nMake sure you have included the generate extras during installation.\n eg. 'pip install2 dcontainer[generate]'"
)
raise typer.Exit(code=1) from e

OCIFeatureGenerator.generate(feature_definition=feature_definition.as_posix(),
output_dir=output_dir.as_posix(),
release_version=release_version)


23 changes: 0 additions & 23 deletions dcontainer/cli/generate/generate_feature.py

This file was deleted.

Empty file removed dcontainer/cli/inspect/__init__.py
Empty file.
14 changes: 0 additions & 14 deletions dcontainer/cli/inspect/extract_devcontainer_feature_dict.py

This file was deleted.

59 changes: 59 additions & 0 deletions dcontainer/cli/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import logging
from typing import List, Optional, Dict

import typer

logger = logging.getLogger(__name__)

app = typer.Typer(pretty_exceptions_show_locals=False, pretty_exceptions_short=False)

app.command()


def _validate_args(value: Optional[List[str]]):
if value is not None:
for arg in value:
splitted_arg = arg.split("=")
if len(splitted_arg) < 2 or len(splitted_arg[0]) == 0:
raise typer.BadParameter("Must be formatted as 'key=value'")
return value


@app.command("devcontainer-feature")
def install_devcontainer_feature(
feature: str,
option: Optional[List[str]] = typer.Option(None, callback=_validate_args),
remote_user: Optional[str] = typer.Option(None, callback=_validate_args),
env: Optional[List[str]] = typer.Option(None, callback=_validate_args),
verbose: bool = False,
) -> None:
from dcontainer.devcontainer.oci_feature_installer import OCIFeatureInstaller

def _key_val_arg_to_dict(args: Optional[List[str]]) -> Dict[str, str]:
if args is None:
return {}

args_dict = {}
for single_arg in args:
single_arg = _strip_if_wrapped_around(single_arg, '"')
arg_name = single_arg.split("=")[0]
arg_value = single_arg[len(arg_name) + 1:]
arg_value = _strip_if_wrapped_around(arg_value, '"')
args_dict[arg_name] = arg_value
return args_dict

def _strip_if_wrapped_around(value: str, char: str) -> str:
if len(char) > 1:
raise ValueError(
"For clarity sake, will only strip one character at a time"
)

if len(value) >= 2 and value[0] == char and value[-1] == char:
return value.strip(char)
return value

options_dict = _key_val_arg_to_dict(option)
envs_dict = _key_val_arg_to_dict(env)

OCIFeatureInstaller.install(feature_ref=feature, envs=envs_dict, options=options_dict, remote_user=remote_user,
verbose=verbose)
Empty file removed dcontainer/cli/install/__init__.py
Empty file.
17 changes: 0 additions & 17 deletions dcontainer/cli/install/install_feature.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from easyfs import Directory, File
from easyfs import Directory
from typing import Optional

from dcontainer.cli.generate.file_models.dependencies_sh import DependenciesSH
from dcontainer.cli.generate.file_models.devcontainer_feature_json import (
from dcontainer.devcontainer.feature_generation.file_models.dependencies_sh import DependenciesSH
from dcontainer.devcontainer.feature_generation.file_models.devcontainer_feature_json import (
DevcontainerFeatureJson,
)
from dcontainer.cli.generate.file_models.install_command_sh import InstallCommandSH
from dcontainer.cli.generate.file_models.install_sh import InstallSH
from dcontainer.models.devcontainer_feature_definition import FeatureDefinition
from dcontainer.devcontainer.feature_generation.file_models.install_command_sh import InstallCommandSH
from dcontainer.devcontainer.feature_generation.file_models.install_sh import InstallSH
from dcontainer.devcontainer.models.devcontainer_feature_definition import FeatureDefinition


class SrcDir(Directory):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from easyfs import Directory

from dcontainer.cli.generate.file_models.scenarios_json import ScenariosJson
from dcontainer.cli.generate.file_models.test_sh import TestSH
from dcontainer.models.devcontainer_feature_definition import (
from dcontainer.devcontainer.feature_generation.file_models.scenarios_json import ScenariosJson
from dcontainer.devcontainer.feature_generation.file_models.test_sh import TestSH
from dcontainer.devcontainer.models.devcontainer_feature_definition import (
FeatureDefinition,
TestScenario,
)
Expand Down
Loading

0 comments on commit 82ed823

Please sign in to comment.