33import re
44from pathlib import Path
55from shutil import rmtree
6- from subprocess import call , check_output
76from textwrap import dedent
8- from typing import Tuple
7+ from typing import List , Tuple
98
109import click
1110from 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 ()
0 commit comments