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
Returns a new instance of CLI.
13 14 15 16 17 18 19 |
# File 'lib/jeeves.rb', line 13 def initialize @options = { all: false, push: false } setup_config_dir end |
Instance Method Details
#parse_options ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jeeves.rb', line 21 def require 'optparse' OptionParser.new do |opts| opts. = 'Usage: jeeves [options]' opts.version = VERSION opts.on('-a', '--all', 'Stage all changes before committing') do @options[:all] = true end opts.on('-p', '--push', 'Push changes after committing') do @options[:push] = true end opts.on('-h', '--help', 'Show this help message') do puts opts exit end end.parse! end |
#run ⇒ Object
43 44 45 46 47 48 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 |
# File 'lib/jeeves.rb', line 43 def run if @options[: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) # 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 @options[:push] puts "Pushing changes..." system('git push') end end |