Sha256: 69f3b910d7c8d9555c081628688e6c8508775846a75701d048d978b9599bf0d0

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Fimon
  class CLI < Thor
    check_unknown_options!

    def self.exit_on_failure?
      true
    end

    desc "init", "Create the configuration file"
    option :config,
           type: :string,
           default: "config/fimon.yml",
           desc: "The configuration file path"
    option :force,
           type: :boolean,
           default: false,
           desc: "Force the file creation, even if there's config file already"
    def init
      config_file = options[:config]

      if File.file?(config_file) && !options[:force]
        interrupt_with_error("The config file #{config_file} already exists")
      end

      FileUtils.mkdir_p(File.dirname(config_file))
      FileUtils.cp File.join(__dir__, "templates/fimon.yml"), config_file
    end

    desc "start", "Start fimon and listens to file changes"
    option :run_on_start,
           type: :boolean,
           default: true,
           desc: "Runs commands on boot"
    option :config,
           type: :string,
           default: "config/fimon.yml",
           desc: "The configuration file path"
    def start
      unless File.file?(options[:config])
        interrupt_with_error(
          "The config file #{options[:config]} doesn't exist"
        )
      end

      Fimon.listen(
        config_file: options[:config],
        run_on_start: options[:run_on_start]
      )
    end

    no_commands do
      private def interrupt_with_error(message)
        shell.say "ERROR: #{message}", :red
        exit 1
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fimon-0.0.1 lib/fimon/cli.rb
fimon-0.0.0 lib/fimon/cli.rb