Sha256: a4c4fc90ad3219fa173f8b699e8327dc3445019c27f81fda3e450e62a8d91e77

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require("optionparser")

module Zapp
  # Provides the CLI utility for easily running Ruby 3.0.0+ applications with Zap
  class CLI
    def run
      parse_options

      Zapp::Server.new.run
    end

    private

    def parse_options
      begin
        parse_config_file(location: "./config/zapp.rb")
      rescue StandardError
        # Ignored
      end

      OptionParser.new do |opts|
        opts.banner = "Usage: bundle exec zapp [options]"

        opts.on("-c", "--config-file=FILE", "Config file to use") do |file|
          parse_config_file(location: file)
        end

        opts.on("-v", "--version", "Prints the version of Zapp currently running") do
          puts("Zapp v#{Zapp::VERSION}")
          exit
        end

        opts.on("-h", "--help", "Prints this help") do
          puts(opts)
          exit
        end
      end.parse!
    end

    def parse_config_file(location:)
      config = File.read(
        File.absolute_path(location)
      )

      Zapp.config.instance_eval(config)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zapp-0.2.6 lib/zapp/cli.rb
zapp-0.2.5 lib/zapp/cli.rb
zapp-0.2.4 lib/zapp/cli.rb
zapp-0.2.3 lib/zapp/cli.rb
zapp-0.2.2 lib/zapp/cli.rb
zapp-0.2.1 lib/zapp/cli.rb
zapp-0.1.1 lib/zapp/cli.rb