Class: Bruh::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/bruh/cli.rb

Overview

CLI interface for Bruh commands

Instance Method Summary collapse

Instance Method Details

#config_get(key) ⇒ Object



144
145
146
147
# File 'lib/bruh/cli.rb', line 144

def config_get(key)
  value = Config.get(key.to_sym)
  puts "#{key}: #{value}"
end

#config_set(key, value) ⇒ Object



150
151
152
153
# File 'lib/bruh/cli.rb', line 150

def config_set(key, value)
  Config.set(key.to_sym, value)
  puts "Set #{key} = #{value}"
end

#config_setupObject



138
139
140
141
# File 'lib/bruh/cli.rb', line 138

def config_setup
  Config.setup_credentials(true)
  puts 'Configuration setup complete.'
end

#releaseObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bruh/cli.rb', line 26

def release
  interactive = !options[:non_interactive]

  project_root = Dir.pwd
  cabal_file = find_cabal_file(project_root)

  if cabal_file.nil?
    puts 'Error: No .cabal file found in current directory or subdirectories'
    exit 1
  end

  cabal = Cabal.new(cabal_file)

  current_version = cabal.version
  puts "Current version: #{current_version}"

  # Determine new version
  if options[:version] && !options[:version].empty?
    new_version = options[:version]
  elsif interactive
    suggested_version = increment_version(current_version)
    new_version = prompt('Enter new version', suggested_version)
  else
    new_version = increment_version(current_version)
  end

  puts "Preparing release for version #{new_version}"

  # Update cabal version
  cabal.update_version(new_version)
  puts "Updated .cabal file to version #{new_version}"

  # Update changelog
  if File.exist?('CHANGELOG.md')
    Changelog.update(new_version, project_root, interactive)
    puts 'Updated CHANGELOG.md with new version entry'
  end

  # Run tests
  puts 'Running tests to verify everything works...'
  unless system('bundle exec rake test')
    puts 'Tests failed. Aborting release process.'
    exit 1 unless yes_no_prompt('Continue anyway?', default_no: false) && interactive
  end

  # Commit changes if in interactive mode
  if interactive && yes_no_prompt('Commit version bump and changelog?', default_no: true)
    system("git add #{cabal_file} CHANGELOG.md")
    system("git commit -m \"Bump version to #{new_version}\"")

    system('git push origin main') if yes_no_prompt('Push changes to origin?', default_no: true)

    if yes_no_prompt("Create tag v#{new_version}?", default_no: true)
      if system("git rev-parse v#{new_version} >/dev/null 2>&1")
        if yes_no_prompt('Tag already exists. Update it?', default_no: true)
          system("git tag -fa v#{new_version} -m \"Release version #{new_version}\"")
        end
      else
        system("git tag -a v#{new_version} -m \"Release version #{new_version}\"")
      end

      system("git push origin v#{new_version}") if yes_no_prompt('Push tag to origin?', default_no: true)
    end
  end

  # Upload to Hackage
  unless options[:skip_hackage]
    puts 'Preparing for Hackage release...'
    hackage = Hackage.new(interactive)

    if interactive
      uploaded = hackage.publish(new_version)
    else
      # In non-interactive mode, use credentials from config
      config = Config.load
      uploaded = hackage.publish_non_interactive(new_version, config[:hackage_username], config[:hackage_password])
    end

    if uploaded
      puts 'Successfully published to Hackage!'

      # Calculate package SHA for Homebrew
      sha256 = hackage.calculate_package_sha256(new_version)

      # Update Homebrew formula
      if sha256
        puts 'Updating Homebrew formula...'
        formula = Homebrew.new(interactive)
        formula.update(new_version, sha256)

        # Build bottle if requested
        unless options[:skip_bottles]
          puts 'Building Homebrew bottle...'
          bottle = Bottle.new(interactive)
          bottle_info = bottle.build(new_version)

          if bottle_info && !options[:skip_github]
            puts 'Uploading bottle to GitHub...'
            bottle.upload_to_github(new_version, bottle_info)

            puts 'Updating formula with bottle information...'
            formula.update_bottle_info(bottle_info)
          end
        end
      end
    end
  end

  puts 'Release process complete!'
end

#versionObject



16
17
18
# File 'lib/bruh/cli.rb', line 16

def version
  puts "Bruh version #{Bruh::VERSION}"
end