Class: Browserctl::Commands::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/commands/init.rb

Constant Summary collapse

CONFIG_TEMPLATE =
<<~YAML
  # browserctl project configuration
  # Uncomment and edit to customise.

  # daemon: default          # named daemon instance (see browserd --name)
  # workflows_dir: .browserctl/workflows
YAML
GITIGNORE_CONTENT =
<<~GITIGNORE
  # State bundles — contain credentials, never commit
  state/
GITIGNORE

Class Method Summary collapse

Class Method Details

.run(_args) ⇒ Object



22
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
48
49
50
# File 'lib/browserctl/commands/init.rb', line 22

def self.run(_args)
  FileUtils.mkdir_p(".browserctl/workflows")
  FileUtils.touch(".browserctl/workflows/.keep")

  FileUtils.mkdir_p(".browserctl/state")

  gitignore_path = ".browserctl/.gitignore"
  File.write(gitignore_path, GITIGNORE_CONTENT) unless File.exist?(gitignore_path)

  config_path = ".browserctl/config.yml"
  File.write(config_path, CONFIG_TEMPLATE) unless File.exist?(config_path)

  payload = {
    ok: true,
    paths: {
      workflows: ".browserctl/workflows",
      state: ".browserctl/state",
      config: ".browserctl/config.yml"
    }
  }
  OutputFormat.current.emit(payload) do
    <<~TEXT.chomp
      Initialised browserctl project:
        .browserctl/workflows/   (place workflow .rb files here)
        .browserctl/state/       (state bundles — git-ignored)
        .browserctl/config.yml   (project settings)
    TEXT
  end
end