Skip to content

Commit

Permalink
fix(pycharm-cli): an error was being raised when opening files
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Mar 5, 2019
1 parent 34f18e8 commit 6e81b31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 15 additions & 10 deletions clit/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import re
from pathlib import Path
from shutil import rmtree
from subprocess import call, check_output
from textwrap import dedent
from typing import Tuple
from typing import List, Tuple

import click
from plumbum import FG, RETCODE
Expand All @@ -30,16 +29,22 @@ def pycharm_cli(files):
If a file doesn't exist, call `which` to find out the real location.
"""
full_paths = []
full_paths: List[str] = []
errors = False
for possible_file in files:
if os.path.isfile(possible_file):
real_file = os.path.abspath(possible_file)
path = Path(possible_file).absolute()
if path.is_file():
full_paths.append(str(path))
else:
real_file = check_output(["which", possible_file]).decode().strip()
full_paths.append(real_file)
command_line = [PYCHARM_MACOS_APP_PATH] + full_paths
click.secho(f"Calling PyCharm with {' '.join(command_line)}", fg="green")
call(command_line)
which_file = shell(f"which {possible_file}", quiet=True, return_lines=True)
if which_file:
full_paths.append(which_file[0])
else:
click.secho(f"File not found on $PATH: {possible_file}", fg="red")
errors = True
if full_paths:
shell(f"{PYCHARM_MACOS_APP_PATH} {' '.join(full_paths)}")
exit(1 if errors else 0)


@click.group()
Expand Down
6 changes: 5 additions & 1 deletion clit/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def backup_full(ctx, dry_run: bool, kill: bool, pictures: bool):


def shell(command_line, quiet=False, return_lines=False, **kwargs):
"""Print and run a shell command."""
"""Print and run a shell command.
:param quiet: Don't print the command line that will be executed.
:param return_lines: Return a list of lines instead of a ``CompletedProcess`` instance.
"""
if not quiet:
click.secho("$ ", fg="magenta", nl=False)
click.secho(command_line, fg="yellow")
Expand Down

0 comments on commit 6e81b31

Please sign in to comment.