Skip to content

Commit

Permalink
Add save argument to settings subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Dec 19, 2024
1 parent e60f8d0 commit f00bf60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions .charla.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"chats_path": "./tests/data/chats/",
"model": "phi3",
"chats_path": "./tests/data/chats/",
"prompt_history": "./tests/data/chats/prompt-history.txt",
"provider": "ollama"
}
"provider": "ollama",
"message_limit": 50,
"multiline": false
}
1 change: 1 addition & 0 deletions charla/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def main(args=None) -> None:

parser_settings = subparsers.add_parser('settings', help='Show current settings.')
parser_settings.add_argument('--location', action='store_true', help='Show location of settings file.')
parser_settings.add_argument('--save', action='store_true', help='Save settings in ".charla.json" file.')
parser_settings.set_defaults(func=config.manage)

argv = parser.parse_args(args)
Expand Down
8 changes: 7 additions & 1 deletion charla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ def manage(argv: argparse.Namespace) -> None:
print(path_settings)
else:
user_settings = {k: v for k, v in vars(argv).items() if k in default_settings}
print(json.dumps(user_settings, indent=4))
out = json.dumps(user_settings, indent=4)
if argv.save:
filename = '.charla.json'
Path(filename).write_text(out)
print(f'Saved settings in {filename}.')
else:
print(out)


def mkdir(path: Path, **kwds):
Expand Down

0 comments on commit f00bf60

Please sign in to comment.