fix: improve CLI options
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Glenn Y. Rolland 2024-01-04 12:42:34 +01:00
parent 218d057071
commit 790152ec36
4 changed files with 42 additions and 11 deletions

View file

@ -79,31 +79,32 @@ make install
## Usage
### Packing directory content
Run Code-Preloader with the following command-line options:
```
CodePreloader v0.1.0
Usage: code-preloader [options] DIR ...
Usage: code-preloader pack [options] DIR ...
Options:
-c FILE, --config=FILE Load parameters from FILE
Global options:
--version Show version
-h, --help Show this help
Pack options:
-i REGEXP, --ignore=REGEXP Ignore file or directory
-o FILE, --output=FILE Write output to FILE
-H FILE, --header-prompt=FILE Load header prompt from FILE
-F FILE, --footer-prompt=FILE Load footer prompt from FILE
--version Show version
-h, --help Show this help
-c FILE, --config=FILE Load parameters from FILE
```
### Examples
#### Basic Use Case
To preload all files in the `src` directory and output to `result.txt`, while
ignoring the `git` the `bin` directory, and the result file itself:
```bash
./bin/code-preloader -o result.txt -i .git -i result.txt -i bin/ src
./bin/code-preloader pack -o result.txt -i .git -i result.txt -i bin/ src
```
#### Advanced Use Case
@ -113,7 +114,7 @@ and appending prompts, while ignoring the `git` the `bin` directory, and the
result file itself:
```bash
./bin/code-preloader \
./bin/code-preloader pack \
-i .git -i bin/ -i result.txt -i prompts \
-H prompts/context.txt -F prompts/request-readme.txt \
src \
@ -122,7 +123,22 @@ result file itself:
__Note__ `ctrlc` is my alias to `xclip -selection clipboard -i`
#### Advanced with configuration file
### Creating a config file
Run Code-Preloader with the following command-line options:
```
Usage: code-preloader init [options]
Global options:
--version Show version
-h, --help Show this help
Init options:
-c FILE, --config=FILE Load parameters from FILE
```
#### Example: Advanced with configuration file
You can also do the same by storing all parameters within a configuration file
(ex: `code_preloader.yml`).

View file

@ -1,5 +1,9 @@
version: 2.0
shards:
completion:
git: https://github.com/f/completion.git
version: 0.1.0+git.commit.d8799381b2de14430496199260eca64eb329625f
magic:
git: https://github.com/dscottboggs/magic.cr.git
version: 1.1.0

View file

@ -16,6 +16,8 @@ dependencies:
github: alexherbo2/walk.cr
version_from_shard:
github: hugopl/version_from_shard
# completion:
# github: f/completion
# description: |
# Short description of chatgpt-preloader

View file

@ -1,5 +1,6 @@
require "option_parser"
require "yaml"
# require "completion"
require "./models/root_config"
require "./version"
@ -72,6 +73,8 @@ module CodePreloader
puts parser
abort("ERROR: Invalid option #{opt}!")
end
# complete_with "code-preloader init", parser
end
def parse_pack_options(parser)
@ -141,6 +144,8 @@ module CodePreloader
puts parser
abort("ERROR: Invalid option #{ex}")
end
# complete_with "code-preloader pack", parser
end
def parse_arguments(args : Array(String))
@ -179,6 +184,8 @@ module CodePreloader
puts parser
abort("ERROR: Invalid option #{ex}")
end
# complete_with "code-preloader", parser
end
@parser.try &.parse(args)
@ -193,6 +200,8 @@ module CodePreloader
case @subcommand
when Subcommand::Init then validate_init
when Subcommand::Pack then validate_pack
when Subcommand::None, Subcommand::Help, Subcommand::Version
# do nothing
else
abort("Unknown subcommand #{@subcommand}")
end