Skip to content

Commit 43a5bae

Browse files
authored
PATH troubleshooting helpers/docs (#321)
* have previous version match command * add __main__.py to enable `python -m code42cli` helper * adjust * add PATH troubleshooting steps to gettingstarted.md * appease flake8 * use powershell markdown blocks * style * IX feedback
1 parent 4c06280 commit 43a5bae

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

docs/userguides/gettingstarted.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ python3 -m pip install code42cli
2222
```
2323

2424
To install a previous version of the Code42 CLI via `pip`, add the version number. For example, to install version
25-
0.4.1, enter:
25+
0.5.3, enter:
2626

2727
```bash
2828
python3 -m pip install code42cli==0.5.3
@@ -123,6 +123,41 @@ To learn more about authenticating in the CLI, follow the [Configure profile gui
123123

124124
## Troubleshooting and support
125125

126+
### Code42 command not found
127+
128+
If your python installation has added itself to your environment's PATH variable, then running `code42` _should_ just work.
129+
130+
However, if after installation the `code42` command is not found, the CLI has some helpers for this (added in version 1.10):
131+
132+
You can execute the CLI by calling the python module directly:
133+
134+
```bash
135+
python3 -m code42cli
136+
```
137+
138+
And the base `code42` command now has a `--script-dir` option that will print out the directory the `code42` script was
139+
installed into, so you can manually add it to your PATH, enabling the `code42` command to work.
140+
141+
#### On Mac/Linux:
142+
143+
Run the following to make `code42` visible in your shell's PATH (to persist the change, add it to your shell's configuration file):
144+
145+
```bash
146+
export PATH=$PATH:$(python3 -m code42cli --script-dir)
147+
```
148+
149+
#### On Windows:
150+
151+
```powershell
152+
$env:Path += ";$(python -m code42cli --script-dir)"
153+
```
154+
155+
To persist the change, add the updated PATH to your registry:
156+
157+
```powershell
158+
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $env:Path
159+
```
160+
126161
### Debug mode
127162

128163
Debug mode may be useful if you are trying to determine if you are experiencing permissions issues. When debug mode is

src/code42cli/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from code42cli.main import cli
2+
3+
cli(prog_name="code42")

src/code42cli/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import signal
3+
import site
24
import sys
35

46
import click
@@ -53,13 +55,28 @@ def exit_on_interrupt(signal, frame):
5355
@click.option(
5456
"--python",
5557
is_flag=True,
56-
help="Print path to the python interpreter env that `code42` is installed in.",
58+
help="Print path to the python interpreter env that `code42cli` is installed in.",
59+
)
60+
@click.option(
61+
"--script-dir",
62+
is_flag=True,
63+
help="Print the directory the `code42` script was installed in (for adding to your PATH if needed).",
5764
)
5865
@sdk_options(hidden=True)
59-
def cli(state, python):
66+
def cli(state, python, script_dir):
6067
if python:
6168
click.echo(sys.executable)
6269
sys.exit(0)
70+
if script_dir:
71+
for root, _dirs, files in os.walk(site.PREFIXES[0]):
72+
if "code42" in files or "code42.exe" in files:
73+
print(root)
74+
sys.exit(0)
75+
76+
for root, _dirs, files in os.walk(site.USER_BASE):
77+
if "code42" in files or "code42.exe" in files:
78+
print(root)
79+
sys.exit(0)
6380

6481

6582
cli.add_command(alerts)

0 commit comments

Comments
 (0)