Skip to content

Commit

Permalink
Breakout argument parser functions for package name and version
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Feb 13, 2020
1 parent c176265 commit 316c43a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
40 changes: 25 additions & 15 deletions ethpm_cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,21 @@ def add_manifest_path_to_parser(
)


def add_package_name_and_package_version_to_parser(
parser: argparse.ArgumentParser, name_msg: str, version_msg: str,
) -> None:
def add_package_name_to_parser(parser: argparse.ArgumentParser, help_msg: str,) -> None:
parser.add_argument(
"--package-name", dest="package_name", action="store", type=str, help=name_msg
"--package-name", dest="package_name", action="store", type=str, help=help_msg
)


def add_package_version_to_parser(
parser: argparse.ArgumentParser, help_msg: str,
) -> None:
parser.add_argument(
"--package-version",
dest="package_version",
action="store",
type=str,
help=version_msg,
help=help_msg,
)


Expand All @@ -159,19 +162,17 @@ def release_cmd(args: argparse.Namespace) -> None:
)

release_package(package_name, package_version, manifest_uri, config)
cli_logger.info(
f"{package_name} v{package_version} @ {manifest_uri} "
)
cli_logger.info(f"{package_name} v{package_version} @ {manifest_uri} ")
else:
release_package(args.package_name, args.package_version, args.manifest_uri, config)
release_package(
args.package_name, args.package_version, args.manifest_uri, config
)
cli_logger.info(
f"{args.package_name} v{args.package_version} @ {args.manifest_uri} "
)

active_registry = get_active_registry(config.xdg_ethpmcli_root / REGISTRY_STORE)
cli_logger.info(
f"released to registry @ {active_registry.uri}."
)
cli_logger.info(f"released to registry @ {active_registry.uri}.")


release_parser = ethpm_parser.add_parser(
Expand All @@ -188,9 +189,12 @@ def release_cmd(args: argparse.Namespace) -> None:
add_manifest_path_to_parser(
release_group, "Local path to target manifest used for release.",
)
add_package_name_and_package_version_to_parser(
add_package_name_to_parser(
release_parser,
"Package name of package you want to release. Must match `package_name` in manifest.",
)
add_package_version_to_parser(
release_parser,
"Version of package you want to release. Must match the `version` field in manifest.",
)
add_keyfile_password_arg_to_parser(release_parser)
Expand Down Expand Up @@ -375,9 +379,12 @@ def create_basic_cmd(args: argparse.Namespace) -> None:
"The generated manifest will package up all available sources and contract types "
"available in the solidity compiler output found in given project directory.",
)
add_package_name_and_package_version_to_parser(
add_package_name_to_parser(
create_basic_parser,
"Package name for generating manifest with `basic-manifest` command.",
)
add_package_version_to_parser(
create_basic_parser,
"Package version for generating manifest with `basic-manifest` command.",
)
add_project_dir_arg_to_parser(create_basic_parser)
Expand Down Expand Up @@ -486,9 +493,12 @@ def install_action(args: argparse.Namespace) -> None:
action="store_true",
help="Flag to use locally running IPFS node rather than defualting to Infura.",
)
add_package_name_and_package_version_to_parser(
add_package_name_to_parser(
install_parser,
"Package name to use when installing a package from etherscan URIs.",
)
add_package_version_to_parser(
install_parser,
"Package version to use when installing a package from etherscan URIs.",
)
add_alias_arg_to_parser(install_parser)
Expand Down
7 changes: 4 additions & 3 deletions tests/core/_utils/test_ipfs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json

from ethpm_cli._utils.ipfs import pin_local_manifest


def test_pin_local_manifest(test_assets_dir):
local_manifest_path = test_assets_dir / "owned" / "1.0.0.json"
expected_manifest = json.loads(
local_manifest_path.read_text()
expected_manifest = json.loads(local_manifest_path.read_text())
(package_name, package_version, manifest_uri) = pin_local_manifest(
local_manifest_path
)
(package_name, package_version, manifest_uri) = pin_local_manifest(local_manifest_path)
assert package_name == expected_manifest["package_name"]
assert package_version == expected_manifest["version"]
assert manifest_uri == "ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW"

0 comments on commit 316c43a

Please sign in to comment.