Class: Jeeves::CLI
- Inherits:
-
Object
- Object
- Jeeves::CLI
- Defined in:
- lib/jeeves.rb
Constant Summary collapse
- CONFIG_DIR =
File.('~/.config/jeeves')
- PROMPT_FILE =
File.join(CONFIG_DIR, 'prompt')
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse_options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
14 15 16 17 18 19 20 21 |
# File 'lib/jeeves.rb', line 14 def initialize = { all: false, push: false, dry_run: false } setup_config_dir end |
Instance Method Details
#parse_options ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jeeves.rb', line 23 def require 'optparse' OptionParser.new do |opts| opts. = 'Usage: jeeves [options]' opts.version = VERSION opts.on('-a', '--all', 'Stage all changes before committing') do [:all] = true end opts.on('-p', '--push', 'Push changes after committing') do [:push] = true end opts.on('-d', '--dry-run', 'Generate commit message without committing') do [:dry_run] = true end opts.on('-h', '--help', 'Show this help message') do puts opts exit end end.parse! end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/jeeves.rb', line 49 def run # Automatically detect stdin input has_stdin_input = !STDIN.tty? || STDIN.closed? # Handle stdin mode when auto-detected if has_stdin_input # Read diff from stdin diff = STDIN.read if diff.empty? puts "Error: No diff content provided via stdin." exit 1 end # Generate commit message and output just the message = (diff, suppress_output: true) puts return end # Normal mode: work with git staged changes if [:all] system('git add -A') end # Get git diff of staged changes diff = `git diff --staged` if diff.empty? puts "No changes staged for commit." exit 1 end # Get AI-generated commit message = (diff) # If dry-run mode, just output the message and exit if [:dry_run] puts "\nDry-run mode: Commit message would be:" puts "============================================" puts puts "============================================" puts "No commit was created (dry-run mode)" return end # Write commit message to temp file for git to use temp_file = File.join(Dir.tmpdir, 'jeeves_commit_message') File.write(temp_file, ) # Commit with the generated message system("git commit -F #{temp_file}") # Clean up temp file File.unlink(temp_file) if File.exist?(temp_file) # Push if requested if [:push] puts "Pushing changes..." system('git push') end end |