Sha256: 23f81180bd65d2759df1320e4818cf9ca8b297fcf2904f0fa008e92f7e6033d3

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require_relative '../command'
require 'os'

module Epuber
  class Command
    class Server < Command
      self.summary = 'Starts web server to display and debug e-book pages.'
      self.arguments = [
        CLAide::Argument.new('TARGET', false, false),
      ]

      def self.options
        [
          ['--open', 'Opens the web page in default web browser, working only on OS X'],
        ].concat(super)
      end

      # @param [CLAide::ARGV] args
      #
      def initialize(args)
        super
        @selected_target_name = args.shift_argument
        @open_web_browser = args.flag?('open', false)
      end

      def validate!
        super
        verify_one_bookspec_exists!

        pre_build_checks
      end

      def run
        super

        require_relative '../server'

        target = if @selected_target_name.nil?
                   book.buildable_targets.first
                 else
                   book.target_named(@selected_target_name)
                 end

        help!('Not existing target') if target.nil?

        begin
          Epuber::Server.run!(book, target, verbose: verbose?) do |uri|
            if OS.osx?
              if @open_web_browser
                system "open #{uri}"
              else
                UI.info 'Web browser can be automatically opened by adding --open flag, see --help'
              end
            end
          end
        rescue Interrupt
          write_lockfile
          raise
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
epuber-0.11.1 lib/epuber/command/server.rb
epuber-0.11.0 lib/epuber/command/server.rb
epuber-0.10.3 lib/epuber/command/server.rb
epuber-0.10.2 lib/epuber/command/server.rb
epuber-0.10.1 lib/epuber/command/server.rb