Class: AstroSubframeOrganizer::Commands::Init
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- AstroSubframeOrganizer::Commands::Init
- 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
Instance Method Summary collapse
- #call(force: false, **options) ⇒ Object
- #default_config(telescope: nil, filter: nil, camera: nil) ⇒ Object
Methods included from EquipmentOptions
Methods included from SharedOptions
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, **) setup(**.slice(:config, :verbose, :skip_confirm)) config_file = [: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(**.slice(:telescope, :filter, :camera)).to_yaml) if [: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 |