Class: AstroSubframeOrganizer::Commands::Init

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
EquipmentOptions, SharedOptions
Defined in:
lib/astro_subframe_organizer/commands/init.rb

Overview

Create default config file at ~/astro-subframe-organizer-config.yml

Instance Attribute Summary

Attributes included from EquipmentOptions

#equipment_selector

Instance Method Summary collapse

Methods included from EquipmentOptions

included, #set_equipment

Methods included from SharedOptions

included, #setup

Instance Method Details

#call(force: false, **options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/astro_subframe_organizer/commands/init.rb', line 23

def call(force: false, **options)
  setup(**options.slice(:config, :verbose, :skip_confirm))

  config_file = options[:config] || File.join(Dir.home, 'astro-subframe-organizer-config.yml')

  if File.exist?(config_file) && !force
    puts "Config file #{config_file} already exists. Use --force to overwrite anyway."
  else
    require 'yaml'
    File.write(config_file, default_config(**options.slice(:telescope, :filter, :camera)).to_yaml)

    if options[:config]
      puts "Created config file at #{config_file}"
    else
      puts 'Created default config file at ~/astro-subframe-organizer-config.yml'
    end
  end

  puts 'Edit this file to customize your telescopes, filters, and cameras.'
end

#default_config(telescope: nil, filter: nil, camera: nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/astro_subframe_organizer/commands/init.rb', line 44

def default_config(telescope: nil, filter: nil, camera: nil)
  {
    'telescopes' => telescope ? [telescope] : Config::DEFAULT_CONFIG.fetch('telescopes'),
    'filters' => filter ? [filter] : Config::DEFAULT_CONFIG.fetch('filters'),
    'cameras' => camera ? [camera] : Config::DEFAULT_CONFIG.fetch('cameras'),
    'temperature_tolerance' => 5.0,
  }
end