Skip to content

Commit 6e81b31

Browse files
committed
fix(pycharm-cli): an error was being raised when opening files
1 parent 34f18e8 commit 6e81b31

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

clit/dev.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import re
44
from pathlib import Path
55
from shutil import rmtree
6-
from subprocess import call, check_output
76
from textwrap import dedent
8-
from typing import Tuple
7+
from typing import List, Tuple
98

109
import click
1110
from plumbum import FG, RETCODE
@@ -30,16 +29,22 @@ def pycharm_cli(files):
3029
3130
If a file doesn't exist, call `which` to find out the real location.
3231
"""
33-
full_paths = []
32+
full_paths: List[str] = []
33+
errors = False
3434
for possible_file in files:
35-
if os.path.isfile(possible_file):
36-
real_file = os.path.abspath(possible_file)
35+
path = Path(possible_file).absolute()
36+
if path.is_file():
37+
full_paths.append(str(path))
3738
else:
38-
real_file = check_output(["which", possible_file]).decode().strip()
39-
full_paths.append(real_file)
40-
command_line = [PYCHARM_MACOS_APP_PATH] + full_paths
41-
click.secho(f"Calling PyCharm with {' '.join(command_line)}", fg="green")
42-
call(command_line)
39+
which_file = shell(f"which {possible_file}", quiet=True, return_lines=True)
40+
if which_file:
41+
full_paths.append(which_file[0])
42+
else:
43+
click.secho(f"File not found on $PATH: {possible_file}", fg="red")
44+
errors = True
45+
if full_paths:
46+
shell(f"{PYCHARM_MACOS_APP_PATH} {' '.join(full_paths)}")
47+
exit(1 if errors else 0)
4348

4449

4550
@click.group()

clit/files.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def backup_full(ctx, dry_run: bool, kill: bool, pictures: bool):
151151

152152

153153
def shell(command_line, quiet=False, return_lines=False, **kwargs):
154-
"""Print and run a shell command."""
154+
"""Print and run a shell command.
155+
156+
:param quiet: Don't print the command line that will be executed.
157+
:param return_lines: Return a list of lines instead of a ``CompletedProcess`` instance.
158+
"""
155159
if not quiet:
156160
click.secho("$ ", fg="magenta", nl=False)
157161
click.secho(command_line, fg="yellow")

0 commit comments

Comments
 (0)