Sha256: 2bc2a778c487410800f5ddb3fde79677a1aabb15f4708711b84d3402734fd5fa

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require "io/console"
module Sapos
  module Print
    include Thor::Actions
    class CLI < Thor
      
      desc "setup", "Setup Wizard"
      def setup
        info 
        config = {}
        
        url = ask("Configuration URL")
        response = RestClient.get(url)
        data = JSON.parse(response)

        config[:q] = data["channel"]
        config[:key] = data["key"]
        config[:printer] = ask("Printer Name: ")
        config[:adapter] = ask("Printer Adapter: ", limited_to: ["console", "cups", "windows"])
        config[:interface] = ask("Interface", limited_to: ["text", "escp"])
        
        if yes?("Are you sure that you want to write the configuration file?")
          Sapos::Print::Configuration.write(config)
          ap config
          say "Configuration Saved! Cheers"
        end        
      end
      
      desc "start", "run service"
      def start
        info
        config = Sapos::Print.config
        puts ["Q=#{config.q.to_s}", "Printer=#{config.printer.to_s}", "Adapter=#{config.adapter.to_s}", "Interface=#{config.interface}"].join("\n")
        
        Sapos::Print::QReader.printer_config = config
        Sapos::Print::QReader.verbose = options[:verbose]
        Sapos::Print::QReader.run!
      end
      
      desc "print", "demo print"
      def print
        info
        config = Sapos::Print.config
        printer = Printer.new(config)
        printer.print("This is a test\nprint page\nwithno special commands")
      end
      
      no_tasks do
        def info
          if @printed.nil?
            @printed ||= begin
              print_wrapped("=+" * 40)
              say("SaposPrint v#{Sapos::Print::VERSION}")
              say "... by Agile Software Development [Copyright © 2016-#{Time.now.year}]"
              print_wrapped("=+" * 40)
              puts "\n"        
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sapos-print-1.0.0 lib/sapos/print/cli.rb