Skip to content

Commit 32c4089

Browse files
committed
use click library for cli
1 parent a88df50 commit 32c4089

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Installing ShellOracle is easy!
4545
```
4646
2. Configure ShellOracle and follow the prompts
4747
```shell
48-
shor configure
48+
shor config init
4949
```
5050
3. Refer to the [providers](#providers) section for specific details regarding your chosen provider.
5151

@@ -97,11 +97,13 @@ Refer to the [Ollama docs](https://ollama.ai) for installation, available models
9797

9898
To use ShellOracle with OpenAI's models, create an [API key](https://platform.openai.com/account/api-keys). Edit
9999
your `~/.shelloracle/config.toml` to change your provider and enter your API key.
100+
You can use `shor config edit` as a shorthand to edit this file.
100101
101102
### Deepseek
102103
103104
To use ShellOracle with Deepseek's models, create an [API key](https://platform.deepseek.com/api_keys). Edit
104105
your `~/.shelloracle/config.toml` to change your provider and enter your API key.
106+
You can use `shor config edit` as a shorthand to edit this file.
105107

106108
### LocalAI
107109

@@ -110,18 +112,21 @@ Refer to the [LocalAI docs](https://localai.io/) for installation, available mod
110112
### XAI
111113

112114
To use ShellOracle with XAI's models, create an [API key](https://docs.x.ai/docs/quickstart#creating-an-api-key).
115+
113116
Edit your `~/.shelloracle/config.toml` to change your provider and enter your API key.
117+
You can use `shor config edit` as a shorthand to edit this file.
114118
115119
### Google
116120
117121
To use ShellOracle with Google's models, create an [API key](https://aistudio.google.com/app/apikey).
118122
Edit your `~/.shelloracle/config.toml` to change your provider and enter your API key.
123+
You can use `shor config edit` as a shorthand to edit this file.
119124

120125
## Configuration
121126

122127
ShellOracle's configuration is your gateway to tailoring the utility to match your preferences and requirements.
123128
The `~/.shelloracle/config.toml` file serves as the control center for customizing various aspects of ShellOracle's
124-
behavior.
129+
behavior. You can quickly access and edit this file using the command `shor config edit`.
125130

126131
## System Requirements
127132

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ dependencies = [
3535
"tomlkit",
3636
"tomli >= 1.1.0; python_version < '3.11'",
3737
"google-generativeai",
38+
"click>=8.1.8",
3839
]
3940

4041
[project.scripts]
41-
shor = "shelloracle.__main__:main"
42+
shor = "shelloracle.cli:main"
4243

4344
[project.urls]
4445
Homepage = "https://github.com/djcopley/ShellOracle"

src/shelloracle/cli/__init__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import logging
2+
import sys
3+
from importlib.metadata import version
4+
5+
import click
6+
7+
from shelloracle import shelloracle
8+
from shelloracle.cli.config import config
9+
from shelloracle.config import initialize_config
10+
from shelloracle.settings import Settings
11+
from shelloracle.tty_log_handler import TtyLogHandler
12+
13+
logger = logging.getLogger(__name__)
14+
15+
16+
def configure_logging():
17+
root_logger = logging.getLogger()
18+
root_logger.setLevel(logging.DEBUG)
19+
20+
file_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
21+
file_handler = logging.FileHandler(Settings.shelloracle_home / "shelloracle.log")
22+
file_handler.setLevel(logging.DEBUG)
23+
file_handler.setFormatter(file_formatter)
24+
25+
tty_formatter = logging.Formatter("%(message)s")
26+
tty_handler = TtyLogHandler()
27+
tty_handler.setLevel(logging.WARNING)
28+
tty_handler.setFormatter(tty_formatter)
29+
30+
root_logger.addHandler(file_handler)
31+
root_logger.addHandler(tty_handler)
32+
33+
34+
@click.group(invoke_without_command=True)
35+
@click.version_option(version=version("shelloracle"))
36+
@click.pass_context
37+
def cli(ctx):
38+
"""ShellOracle command line interface."""
39+
configure_logging()
40+
41+
# If no subcommand is invoked, run the main CLI
42+
if ctx.invoked_subcommand is None:
43+
try:
44+
initialize_config()
45+
except FileNotFoundError:
46+
logger.warning("ShellOracle configuration not found. Run `shor config init` to initialize.")
47+
sys.exit(1)
48+
49+
shelloracle.cli()
50+
51+
52+
cli.add_command(config)
53+
54+
55+
def main():
56+
cli()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import click
2+
3+
from shelloracle.cli.config.init import init
4+
5+
6+
@click.group()
7+
def config(): ...
8+
9+
10+
config.add_command(init)

src/shelloracle/cli/config/init.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import click
2+
3+
4+
@click.command()
5+
def init():
6+
"""Install shelloracle keybindings."""
7+
# nest this import in a function to avoid expensive module loads
8+
from shelloracle.bootstrap import bootstrap_shelloracle
9+
10+
bootstrap_shelloracle()

uv.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)