create-step
Cria um novo step para o bootstrap macOS. Use quando o usuário pedir para adicionar uma nova configuração ou instalação ao bootstrap.
When & Why to Use This Skill
This Claude skill automates the expansion of macOS bootstrap frameworks by generating standardized Ruby step definitions and their corresponding test files. It streamlines the process of adding new system configurations or software installations, ensuring that every new step follows best practices for idempotency and includes a robust testing scaffold.
Use Cases
- Case 1: Rapidly scaffolding new Homebrew package installations or system-level configurations within a macOS setup script.
- Case 2: Implementing idempotent system tweaks (e.g., modifying macOS 'defaults' or plist files) with pre-built logic for checking existing states.
- Case 3: Generating boilerplate Minitest files to ensure high code quality and reliability for environment provisioning scripts.
- Case 4: Standardizing the development workflow for teams maintaining shared 'dotfiles' or automated machine setup runbooks.
| name | create-step |
|---|---|
| description | Cria um novo step para o bootstrap macOS. Use quando o usuário pedir para adicionar uma nova configuração ou instalação ao bootstrap. |
Criar Novo Step para Bootstrap
Estrutura de um Step
Cada step precisa de dois arquivos:
lib/bootstrap/steps/<nome>.rb- Implementaçãotest/steps/<nome>_test.rb- Testes
Template do Step
# frozen_string_literal: true
require_relative '../step'
module Bootstrap
module Steps
class NomeDoStep < Step
def name
'Nome para Exibição'
end
def installed?
# Retorna true se já está configurado (idempotência)
# Exemplos:
# - shell.file_exists?(path)
# - shell.directory_exists?(path)
# - shell.success?('which comando')
# - Verificar conteúdo de arquivo de configuração
end
def install!
# Executa a instalação/configuração
# Use shell.run(command) para comandos não-interativos
# Use shell.run_interactive(command) para comandos que precisam de TTY
end
private
# Métodos auxiliares privados
end
end
end
Template do Teste
# frozen_string_literal: true
require_relative '../test_helper'
require 'bootstrap/steps/<nome>'
class NomeDoStepTest < Minitest::Test
class MockShell
attr_accessor :commands_run, :run_results, :existing_files, :success_results
def initialize
@commands_run = []
@run_results = {}
@existing_files = []
@success_results = {}
end
def run(command)
@commands_run << command
@run_results[command] || Struct.new(:success?, :stderr, :output).new(true, '', '')
end
def run_interactive(command)
@commands_run << command
@run_results[command] || Struct.new(:success?, :stderr, :output).new(true, '', '')
end
def file_exists?(path)
@existing_files.include?(path)
end
def directory_exists?(path)
@existing_files.include?(path)
end
def success?(command)
@commands_run << command
@success_results.fetch(command, false)
end
end
def setup
@shell = MockShell.new
@step = Bootstrap::Steps::NomeDoStep.new(shell: @shell)
end
def test_name
assert_equal 'Nome para Exibição', @step.name
end
def test_installed_returns_false_when_not_configured
# Configure mock para retornar estado não-instalado
refute @step.installed?
end
def test_installed_returns_true_when_configured
# Configure mock para retornar estado instalado
assert @step.installed?
end
def test_install_executes_expected_commands
@step.install!
# Verifique comandos executados
assert_includes @shell.commands_run, 'comando esperado'
end
def test_run_skips_when_already_configured
# Configure mock para estado instalado
result = @step.run!
assert_equal :skipped, result[:status]
end
end
Checklist
- Criar
lib/bootstrap/steps/<nome>.rb - Implementar
name,installed?,install! - Criar
test/steps/<nome>_test.rb - Adicionar require em
bin/bootstrap - Adicionar step na lista de steps em
bin/bootstrap - Rodar
rake testpara validar
Comandos Shell Disponíveis
| Método | Uso |
|---|---|
shell.run(cmd) |
Executa comando, captura output |
shell.run_interactive(cmd) |
Executa com TTY (para sudo, etc) |
shell.success?(cmd) |
Retorna true/false |
shell.file_exists?(path) |
Verifica arquivo |
shell.directory_exists?(path) |
Verifica diretório |
Resultado de shell.run
result = shell.run('comando')
result.success? # true/false
result.output # stdout (stripped)
result.stdout # stdout raw
result.stderr # stderr
Exemplos de installed?
# Verificar se programa existe
def installed?
shell.success?('which programa')
end
# Verificar se arquivo de configuração existe
def installed?
shell.file_exists?(CONFIG_PATH)
end
# Verificar valor de configuração
def installed?
result = shell.run('defaults read com.apple.dock tilesize')
result.success? && result.output.strip.to_i == 36
end
# Combinar múltiplas verificações
def installed?
programa_instalado? && configuracao_correta?
end
Exemplos de install!
# Instalar via Homebrew
def install!
result = shell.run('brew install programa')
raise "Falhou: #{result.stderr}" unless result.success?
end
# Comando interativo (precisa de senha)
def install!
result = shell.run_interactive('sudo comando')
raise 'Falhou' unless result.success?
end
# Criar arquivo de configuração
def install!
File.write(CONFIG_PATH, CONFIG_CONTENT)
end
# Múltiplas etapas
def install!
instalar_dependencia
configurar_sistema
reiniciar_servico
end