Skip to content

Commit 9787fd0

Browse files
author
Nat Chin
authored
Adds --always-install flag to solc-select use (#79)
* Added input request when setting version that's not installed * Added test for prompting * added --always-install flag
1 parent 337c9ba commit 9787fd0

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

scripts/test_solc.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,23 @@ if [[ "$execute" != *"Error: Explicit type conversion not allowed"* ]]; then
9292
exit 255
9393
fi
9494
echo "SUCCESS: solc080_fail_compile"
95+
96+
UNINSTALL_PATH=$HOME/.solc-select/artifacts/solc-0.8.9
97+
rm -rf $UNINSTALL_PATH # uninstall solc 0.8.9
98+
execute=$(solc-select use 0.8.9 --always-install)
99+
if [[ "$execute" != *"Switched global version to 0.8.9"* ]]; then
100+
echo "FAILED: use - always install"
101+
exit 255
102+
fi
103+
echo "SUCCESS: use - always install"
104+
105+
UNINSTALL_PATH=$HOME/.solc-select/artifacts/solc-0.8.1
106+
rm -rf $UNINSTALL_PATH # uninstall solc 0.8.1
107+
execute=$(solc-select use 0.8.1 2>&1)
108+
if [[ $execute != *"'0.8.1' must be installed prior to use"* ]]; then
109+
echo "FAILED: use - no install"
110+
exit 255
111+
fi
112+
echo "SUCCESS: use - no install"
113+
114+
solc-select install 0.8.1 &> /dev/null

solc_select/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def solc_select() -> None:
3737
)
3838
parser_use = subparsers.add_parser("use", help="change the version of global solc compiler")
3939
parser_use.add_argument(
40-
USE_VERSION, help="solc version you want to use (eg: 0.4.25)", type=valid_version
40+
USE_VERSION, help="solc version you want to use (eg: 0.4.25)", type=valid_version, nargs="?"
4141
)
42+
parser_use.add_argument("--always-install", action="store_true")
4243
parser_use = subparsers.add_parser("versions", help="prints out all installed solc versions")
4344
parser_use.add_argument(SHOW_VERSIONS, nargs="*", help=argparse.SUPPRESS)
4445
parser_use = subparsers.add_parser("update", help="upgrades solc-select")
@@ -56,7 +57,7 @@ def solc_select() -> None:
5657
install_artifacts(args.get(INSTALL_VERSIONS))
5758

5859
elif args.get(USE_VERSION) is not None:
59-
switch_global_version(args.get(USE_VERSION))
60+
switch_global_version(args.get(USE_VERSION), args.get("always_install"))
6061

6162
elif args.get(SHOW_VERSIONS) is not None:
6263
res = current_version()

solc_select/solc_select.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def current_version() -> (str, str):
5454
raise argparse.ArgumentTypeError(
5555
"No solc version set. Run `solc-select use VERSION` or set SOLC_VERSION environment variable."
5656
)
57-
return None
5857
return (version, source)
5958

6059

@@ -155,15 +154,17 @@ def get_url(version: str = "", artifact: str = "") -> (str, str):
155154
)
156155

157156

158-
def switch_global_version(version: str) -> None:
157+
def switch_global_version(version: str, always_install: bool) -> None:
159158
if version in installed_versions():
160159
with open(f"{solc_select_dir}/global-version", "w") as f:
161160
f.write(version)
162161
print("Switched global version to", version)
163162
elif version in get_available_versions():
164-
raise argparse.ArgumentTypeError(
165-
f"You need to install '{version}' prior to using it. Use `solc-select install {version}`"
166-
)
163+
if always_install:
164+
install_artifacts(version)
165+
switch_global_version(version, always_install)
166+
else:
167+
raise argparse.ArgumentTypeError(f"'{version}' must be installed prior to use.")
167168
else:
168169
raise argparse.ArgumentTypeError(f"Unknown version '{version}'")
169170

0 commit comments

Comments
 (0)