Skip to content

Commit a01fb1a

Browse files
authored
Merge pull request #52 from seankim658/warning-flag
Warning flag
2 parents 1b7a2e3 + 4bd3a3f commit a01fb1a

7 files changed

Lines changed: 92 additions & 70 deletions

File tree

cli/completions/codeprompt-completions.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _codeprompt() {
3131

3232
case "${cmd}" in
3333
codeprompt)
34-
opts="-d -u -c -o -l -t -h -V --include --exclude --exclude-priority --exclude-from-tree --gitignore --diff-staged --diff-unstaged --no-tokens --encoding --output --no-line-numbers --no-codeblock --relative-paths --no-clipboard --template --no-spinner --json --issue --verbose --help --version [PATH] completion help"
34+
opts="-d -u -c -o -l -t -h -V --include --exclude --exclude-priority --exclude-from-tree --gitignore --diff-staged --diff-unstaged --no-tokens --encoding --output --no-line-numbers --no-codeblock --relative-paths --no-clipboard --template --no-spinner --json --issue --verbose --no-warnings --help --version [PATH] completion help"
3535
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
3636
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
3737
return 0

cli/completions/codeprompt-completions.fish

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
22
function __fish_codeprompt_global_optspecs
3-
string join \n include= exclude= exclude-priority exclude-from-tree gitignore d/diff-staged u/diff-unstaged no-tokens c/encoding= o/output= l/no-line-numbers no-codeblock relative-paths no-clipboard t/template= no-spinner json issue= verbose h/help V/version
3+
string join \n include= exclude= exclude-priority exclude-from-tree gitignore d/diff-staged u/diff-unstaged no-tokens c/encoding= o/output= l/no-line-numbers no-codeblock relative-paths no-clipboard t/template= no-spinner json issue= verbose no-warnings h/help V/version
44
end
55

66
function __fish_codeprompt_needs_command
@@ -43,6 +43,7 @@ complete -c codeprompt -n "__fish_codeprompt_needs_command" -l no-clipboard -d '
4343
complete -c codeprompt -n "__fish_codeprompt_needs_command" -l no-spinner -d 'Whether to render the spinner'
4444
complete -c codeprompt -n "__fish_codeprompt_needs_command" -l json -d 'Whether to print the output as JSON. Defaults to False'
4545
complete -c codeprompt -n "__fish_codeprompt_needs_command" -l verbose -d 'Run in verbose mode to investigate glob pattern matching'
46+
complete -c codeprompt -n "__fish_codeprompt_needs_command" -l no-warnings -d 'Ignore all warnings (sensitive files, large token counts, template warnings)'
4647
complete -c codeprompt -n "__fish_codeprompt_needs_command" -s h -l help -d 'Print help (see more with \'--help\')'
4748
complete -c codeprompt -n "__fish_codeprompt_needs_command" -s V -l version -d 'Print version'
4849
complete -c codeprompt -n "__fish_codeprompt_needs_command" -a "completion" -d 'Generate shell completion scripts.'

cli/completions/codeprompt-completions.ps1

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,43 @@ Register-ArgumentCompleter -Native -CommandName 'codeprompt' -ScriptBlock {
2121

2222
$completions = @(switch ($command) {
2323
'codeprompt' {
24-
[CompletionResult]::new('--include', 'include', [CompletionResultType]::ParameterName, 'Glob patterns to include')
25-
[CompletionResult]::new('--exclude', 'exclude', [CompletionResultType]::ParameterName, 'Glob patterns to exclude')
26-
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Tokenizer to use for token count')
27-
[CompletionResult]::new('--encoding', 'encoding', [CompletionResultType]::ParameterName, 'Tokenizer to use for token count')
28-
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Redirect output to file')
29-
[CompletionResult]::new('--output', 'output', [CompletionResultType]::ParameterName, 'Redirect output to file')
30-
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Optional path to Handlebars template')
31-
[CompletionResult]::new('--template', 'template', [CompletionResultType]::ParameterName, 'Optional path to Handlebars template')
32-
[CompletionResult]::new('--issue', 'issue', [CompletionResultType]::ParameterName, 'Fetch a specific Github issue for the repository')
33-
[CompletionResult]::new('--exclude-priority', 'exclude-priority', [CompletionResultType]::ParameterName, 'Change pattern priority in case of conflict to prioritize the exclusion pattern')
34-
[CompletionResult]::new('--exclude-from-tree', 'exclude-from-tree', [CompletionResultType]::ParameterName, 'Eclude files/folders from the source tree based on exclude patterns')
35-
[CompletionResult]::new('--gitignore', 'gitignore', [CompletionResultType]::ParameterName, 'Don''t respect .gitignore file')
36-
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Capture the git diff for staged changes only (equivalent to running `git diff --cached` or `git diff --staged`')
37-
[CompletionResult]::new('--diff-staged', 'diff-staged', [CompletionResultType]::ParameterName, 'Capture the git diff for staged changes only (equivalent to running `git diff --cached` or `git diff --staged`')
38-
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Capture the git diff for unstaged changes only (equivalent to running `git diff`)')
39-
[CompletionResult]::new('--diff-unstaged', 'diff-unstaged', [CompletionResultType]::ParameterName, 'Capture the git diff for unstaged changes only (equivalent to running `git diff`)')
40-
[CompletionResult]::new('--no-tokens', 'no-tokens', [CompletionResultType]::ParameterName, 'Don''t display approximate token count of the genrated prompt')
41-
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Turn off line numbers in source code blocks')
42-
[CompletionResult]::new('--no-line-numbers', 'no-line-numbers', [CompletionResultType]::ParameterName, 'Turn off line numbers in source code blocks')
43-
[CompletionResult]::new('--no-codeblock', 'no-codeblock', [CompletionResultType]::ParameterName, 'Disable wrapping code inside markdown code blocks')
44-
[CompletionResult]::new('--relative-paths', 'relative-paths', [CompletionResultType]::ParameterName, 'Use relative paths instead of absolute paths, including parent directory')
45-
[CompletionResult]::new('--no-clipboard', 'no-clipboard', [CompletionResultType]::ParameterName, 'Disable copying to clipboard')
46-
[CompletionResult]::new('--no-spinner', 'no-spinner', [CompletionResultType]::ParameterName, 'Whether to render the spinner')
47-
[CompletionResult]::new('--json', 'json', [CompletionResultType]::ParameterName, 'Whether to print the output as JSON. Defaults to False')
48-
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Run in verbose mode to investigate glob pattern matching')
49-
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
50-
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
51-
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
52-
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
24+
[CompletionResult]::new('--include', '--include', [CompletionResultType]::ParameterName, 'Glob patterns to include')
25+
[CompletionResult]::new('--exclude', '--exclude', [CompletionResultType]::ParameterName, 'Glob patterns to exclude')
26+
[CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Tokenizer to use for token count')
27+
[CompletionResult]::new('--encoding', '--encoding', [CompletionResultType]::ParameterName, 'Tokenizer to use for token count')
28+
[CompletionResult]::new('-o', '-o', [CompletionResultType]::ParameterName, 'Redirect output to file')
29+
[CompletionResult]::new('--output', '--output', [CompletionResultType]::ParameterName, 'Redirect output to file')
30+
[CompletionResult]::new('-t', '-t', [CompletionResultType]::ParameterName, 'Optional path to Handlebars template')
31+
[CompletionResult]::new('--template', '--template', [CompletionResultType]::ParameterName, 'Optional path to Handlebars template')
32+
[CompletionResult]::new('--issue', '--issue', [CompletionResultType]::ParameterName, 'Fetch a specific Github issue for the repository')
33+
[CompletionResult]::new('--exclude-priority', '--exclude-priority', [CompletionResultType]::ParameterName, 'Change pattern priority in case of conflict to prioritize the exclusion pattern')
34+
[CompletionResult]::new('--exclude-from-tree', '--exclude-from-tree', [CompletionResultType]::ParameterName, 'Eclude files/folders from the source tree based on exclude patterns')
35+
[CompletionResult]::new('--gitignore', '--gitignore', [CompletionResultType]::ParameterName, 'Don''t respect .gitignore file')
36+
[CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Capture the git diff for staged changes only (equivalent to running `git diff --cached` or `git diff --staged`')
37+
[CompletionResult]::new('--diff-staged', '--diff-staged', [CompletionResultType]::ParameterName, 'Capture the git diff for staged changes only (equivalent to running `git diff --cached` or `git diff --staged`')
38+
[CompletionResult]::new('-u', '-u', [CompletionResultType]::ParameterName, 'Capture the git diff for unstaged changes only (equivalent to running `git diff`)')
39+
[CompletionResult]::new('--diff-unstaged', '--diff-unstaged', [CompletionResultType]::ParameterName, 'Capture the git diff for unstaged changes only (equivalent to running `git diff`)')
40+
[CompletionResult]::new('--no-tokens', '--no-tokens', [CompletionResultType]::ParameterName, 'Don''t display approximate token count of the genrated prompt')
41+
[CompletionResult]::new('-l', '-l', [CompletionResultType]::ParameterName, 'Turn off line numbers in source code blocks')
42+
[CompletionResult]::new('--no-line-numbers', '--no-line-numbers', [CompletionResultType]::ParameterName, 'Turn off line numbers in source code blocks')
43+
[CompletionResult]::new('--no-codeblock', '--no-codeblock', [CompletionResultType]::ParameterName, 'Disable wrapping code inside markdown code blocks')
44+
[CompletionResult]::new('--relative-paths', '--relative-paths', [CompletionResultType]::ParameterName, 'Use relative paths instead of absolute paths, including parent directory')
45+
[CompletionResult]::new('--no-clipboard', '--no-clipboard', [CompletionResultType]::ParameterName, 'Disable copying to clipboard')
46+
[CompletionResult]::new('--no-spinner', '--no-spinner', [CompletionResultType]::ParameterName, 'Whether to render the spinner')
47+
[CompletionResult]::new('--json', '--json', [CompletionResultType]::ParameterName, 'Whether to print the output as JSON. Defaults to False')
48+
[CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'Run in verbose mode to investigate glob pattern matching')
49+
[CompletionResult]::new('--no-warnings', '--no-warnings', [CompletionResultType]::ParameterName, 'Ignore all warnings (sensitive files, large token counts, template warnings)')
50+
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
51+
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
52+
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')
53+
[CompletionResult]::new('--version', '--version', [CompletionResultType]::ParameterName, 'Print version')
5354
[CompletionResult]::new('completion', 'completion', [CompletionResultType]::ParameterValue, 'Generate shell completion scripts.')
5455
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
5556
break
5657
}
5758
'codeprompt;completion' {
58-
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
59-
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
59+
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
60+
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
6061
break
6162
}
6263
'codeprompt;help' {

cli/completions/codeprompt-completions.zsh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ _codeprompt() {
1515

1616
local context curcontext="$curcontext" state line
1717
_arguments "${_arguments_options[@]}" : \
18-
'--include=[Glob patterns to include]:INCLUDE: ' \
19-
'--exclude=[Glob patterns to exclude]:EXCLUDE: ' \
20-
'-c+[Tokenizer to use for token count]:ENCODING: ' \
21-
'--encoding=[Tokenizer to use for token count]:ENCODING: ' \
22-
'-o+[Redirect output to file]:OUTPUT: ' \
23-
'--output=[Redirect output to file]:OUTPUT: ' \
18+
'--include=[Glob patterns to include]:INCLUDE:_default' \
19+
'--exclude=[Glob patterns to exclude]:EXCLUDE:_default' \
20+
'-c+[Tokenizer to use for token count]:ENCODING:_default' \
21+
'--encoding=[Tokenizer to use for token count]:ENCODING:_default' \
22+
'-o+[Redirect output to file]:OUTPUT:_default' \
23+
'--output=[Redirect output to file]:OUTPUT:_default' \
2424
'-t+[Optional path to Handlebars template]:TEMPLATE:_files' \
2525
'--template=[Optional path to Handlebars template]:TEMPLATE:_files' \
26-
'--issue=[Fetch a specific Github issue for the repository]:ISSUE: ' \
26+
'--issue=[Fetch a specific Github issue for the repository]:ISSUE:_default' \
2727
'--exclude-priority[Change pattern priority in case of conflict to prioritize the exclusion pattern]' \
2828
'--exclude-from-tree[Eclude files/folders from the source tree based on exclude patterns]' \
2929
'--gitignore[Don'\''t respect .gitignore file]' \
@@ -40,6 +40,7 @@ _codeprompt() {
4040
'--no-spinner[Whether to render the spinner]' \
4141
'--json[Whether to print the output as JSON. Defaults to False]' \
4242
'--verbose[Run in verbose mode to investigate glob pattern matching]' \
43+
'--no-warnings[Ignore all warnings (sensitive files, large token counts, template warnings)]' \
4344
'-h[Print help (see more with '\''--help'\'')]' \
4445
'--help[Print help (see more with '\''--help'\'')]' \
4546
'-V[Print version]' \

cli/src/main.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ struct Args {
102102
/// Run in verbose mode to investigate glob pattern matching.
103103
#[arg(long, action(ArgAction::SetTrue))]
104104
verbose: bool,
105+
106+
/// Ignore all warnings (sensitive files, large token counts, template warnings).
107+
#[arg(long, action(ArgAction::SetTrue))]
108+
no_warnings: bool,
105109
}
106110

107111
#[derive(Subcommand, Debug)]
@@ -158,13 +162,18 @@ async fn main() -> Result<(), Error> {
158162
args.issue,
159163
&args.template,
160164
);
161-
// Check for git repo first since it will exit if not found
165+
162166
if let Err(error) = validation_config.validate_git_repo(&project_root) {
163167
eprintln!("{}", error.format());
164168
std::process::exit(1);
165169
}
170+
166171
// Get other warnings
167-
let mut warnings = validation_config.validate();
172+
let mut warnings = if !args.no_warnings {
173+
validation_config.validate()
174+
} else {
175+
Vec::new()
176+
};
168177

169178
let (template, template_name) = get_template(&args.template)?;
170179
let handlebars = setup_handlebars_registry(&template, template_name)?;
@@ -181,7 +190,10 @@ async fn main() -> Result<(), Error> {
181190
args.gitignore,
182191
)?;
183192

184-
if !sensitive_files.is_empty() && !prompt_for_sensitive_files(&sensitive_files) {
193+
if !args.no_warnings
194+
&& !sensitive_files.is_empty()
195+
&& !prompt_for_sensitive_files(&sensitive_files)
196+
{
185197
eprintln!(
186198
"\n{}{}{} {}",
187199
"[".bold().white(),
@@ -315,7 +327,7 @@ async fn main() -> Result<(), Error> {
315327
};
316328

317329
// Add token count warning if needed
318-
if !args.no_clipboard {
330+
if !args.no_clipboard && !args.no_warnings {
319331
if let Some(warning) = validate_token_count(tokens) {
320332
warnings.push(warning);
321333
}
@@ -350,7 +362,7 @@ async fn main() -> Result<(), Error> {
350362
let should_copy_to_clipboard = if args.no_clipboard {
351363
false
352364
} else if !args.no_tokens {
353-
validate_clipboard_copy(tokens)
365+
validate_clipboard_copy(tokens, args.no_warnings)
354366
} else {
355367
true
356368
};
@@ -380,7 +392,7 @@ async fn main() -> Result<(), Error> {
380392
}
381393

382394
// Print warnings if needed
383-
if !warnings.is_empty() {
395+
if !args.no_warnings && !warnings.is_empty() {
384396
for warning in warnings {
385397
eprintln!("{}", warning.format());
386398
}

cli/src/validation.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,18 @@ pub fn validate_token_count(token_count: usize) -> Option<ValidationWarning> {
150150
/// ### Arguments
151151
///
152152
/// - `token_count`: The number of tokens in the output.
153+
/// - `no_warnings`: Whether to skip all warnings and prompts.
153154
///
154155
/// ### Returns
155156
///
156157
/// - `bool`: True if clipboard copy should proceed, False otherwise.
157158
///
158-
pub fn validate_clipboard_copy(token_count: usize) -> bool {
159+
pub fn validate_clipboard_copy(token_count: usize, no_warnings: bool) -> bool {
160+
// TODO : This is hacky, should probably handle this directly in main
161+
if no_warnings {
162+
return true
163+
}
164+
159165
if token_count > CLIPBOARD_TOKEN_THRESHOLD {
160166
prompt_for_large_clipboard(token_count)
161167
} else {

0 commit comments

Comments
 (0)