Class: Pasu::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/pasu/runner.rb

Instance Method Summary collapse

Constructor Details

#initializeRunner



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pasu/runner.rb', line 3

def initialize
  OptionParser.new do |p|
    p.banner = 'Usage: pasu [options]'

    p.separator ''
    p.separator 'Options:'

    p.on('-v', '--version', 'Print version.') do
      puts "Pasu #{VERSION} (https://github.com/tbuehlmann/pasu)"
      exit
    end

    p.on('-d', '--directory DIRECTORY', 'Set the base directory for listing files. (Default: pwd)') do |dir|
      directory = Pathname.new(dir).expand_path

      if directory.directory?
        options[:directory] = directory
      else
        puts "Couldn't find directory #{dir}"
        exit 1
      end
    end

    p.on('--no-recursion', "Don't recursively list directories. (Default: false)") do
      options[:recursive] = false
    end

    p.on('--no-dotfiles', "Don't list dotfiles. (Default: false)") do
      options[:dotfiles] = false
    end

    p.on('-u', '--upload', 'Allow uploading of files. (Default: false)') do
      options[:upload] = true
    end

    p.on('--basic-auth USER:PW', 'Only allowing requests with valid user/pw combination provided. (Default: None)') do |access|
      username, password = access.split(':')
      options[:basic_auth] ||= {}
      options[:basic_auth][username] = password
    end

    p.on('-b', '--bind HOST', 'Bind the server to the given host. (Default: 0.0.0.0)') do |host|
      options[:host] = host
    end

    p.on('-p', '--port PORT', 'Bind the server to the given port. (Default: 8080)') do |port|
      options[:port] = Integer(port)
    end

    p.on('-s', '--server RACK_HANDLER', 'Use your own rack handler. (Default: Puma)') do |handler|
      options[:handler] = handler
    end

    p.on_tail('-h', '--help', 'Show this message.') do
      puts p
      exit
    end
  end.parse!
end

Instance Method Details

#optionsObject



63
64
65
# File 'lib/pasu/runner.rb', line 63

def options
  @options ||= {}
end

#runObject



67
68
69
70
71
72
73
74
75
# File 'lib/pasu/runner.rb', line 67

def run
  Pasu::Application.setup(options)

  begin
    Pasu::Application.run
  rescue Errno::EADDRINUSE
    puts "Port #{options[:port]} is already in use. Quitting."
  end
end