Module: Smeagol::CLI

Extended by:
CLI
Included in:
CLI
Defined in:
lib/smeagol/cli.rb

Overview

Smeagol::CLI module is a function module that provide all command line interfaces.

Instance Method Summary collapse

Instance Method Details

#init(argv) ⇒ Object

Initialize Gollum wiki site for use with Smeagol.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smeagol/cli.rb', line 13

def init(argv)
  parser.banner = "usage: smeagol-init [OPTIONS] [WIKI-URI]\n"

  parser.on('-t', '--title [TITLE]') do |title|
    options[:title] = title
  end

  parser.on('-i', '--index [PAGE]') do |page_name|
    options[:index] = page_name
  end

  # TODO: support more settings options for creating setup

  Console.init(*parse(argv))
end

#optionsHash (private)

Command line options.

Returns:

  • (Hash)

    Returns the command line options.


118
119
120
# File 'lib/smeagol/cli.rb', line 118

def options
  @options ||= {}
end

#parse(argv) ⇒ Array (private)

Read command line options into `options` hash.

Returns:

  • (Array)

    Returns arguments and options.


127
128
129
130
131
132
133
134
135
136
# File 'lib/smeagol/cli.rb', line 127

def parse(argv)
  begin
    parser.parse!(argv)
  rescue ::OptionParser::InvalidOption
    puts "smeagol: #{$!.message}"
    puts "smeagol: try 'smeagol --help' for more information"
    exit 1
  end
  return *(argv + [options])
end

#parserOptionParser (private)

Create and cache option parser.

Returns:

  • (OptionParser)

    Returns option parser instance.


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/smeagol/cli.rb', line 143

def parser
  @parser ||= (
    parser = ::OptionParser.new
    parser.on_tail('--quiet', 'Turn on $QUIET mode.') do
      $QUIET = true
    end
    parser.on_tail('--debug', 'Turn on $DEBUG mode.') do
      $DEBUG = true
    end
    parser.on_tail('-v', '--version', 'Display current version.') do
      puts "Smeagol #{Smeagol::VERSION}"
      exit 0
    end
    parser.on_tail('-h', '-?', '--help', 'Display this help screen.') do
      puts parser
      exit 0
    end
    parser
  )
end

#preview(argv) ⇒ Object

Preview current Gollum wiki.


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
# File 'lib/smeagol/cli.rb', line 32

def preview(argv)
  parser.banner = "Usage: smeagol-preview [OPTIONS]\n"

  parser.on('--port [PORT]', 'Bind port (default 4567).') do |port|
    options[:port] = port.to_i
  end

  parser.on('--[no-]cache', 'Enables page caching.') do |flag|
    options[:cache] = flag
  end

  parser.on('--mount-path', 'Serve website from this base path.') do |path|
    options[:mount_path] = path
  end

  #parser.on('--auto-update', 'Updates the repository on a daily basis.') do |flag|
  #  options[:auto_update] = flag
  #end

  #parser.on('--secret [KEY]', 'Specifies the secret key used to update.') do |str|
  #  options[:secret] = str
  #end

  $stderr.puts "Starting preview..."

  Console.preview(*parse(argv))
end

#serve(argv) ⇒ Object

Serve all Gollum repositories as setup in Deagol config file. This can be used to serve sites in production. It makes use of cnames to serve multiple sites via a single service.


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/smeagol/cli.rb', line 65

def serve(argv)
  config_file = nil

  parser.banner = "usage: smeagol-serve [OPTIONS]\n"

  parser.on('-c', '--config [PATH]', 'Load config file instead of default.') do |path|
    options[:config_file] = path
  end

  parser.on('--port [PORT]', 'Bind port (default 4567).') do |port|
    options[:port] = port.to_i
  end

  parser.on('--[no-]cache', 'Enables page caching.') do |flag|
    options[:cache] = flag
  end

  parser.on('--mount-path', 'Serve website from this base path.') do |path|
    options[:mount_path] = path
  end

  parser.on('--auto-update', 'Updates the repository on a daily basis.') do |flag|
    options[:auto_update] = flag
  end

  parser.on('--secret [KEY]', 'Specifies the secret key, if needed to update.') do |str|
    options[:secret] = str
  end

  Console.serve(*parse(argv))
end

#update(argv) ⇒ Object

Update wiki repo and update/clone site repo, if designated in settings.


101
102
103
104
105
106
107
108
109
# File 'lib/smeagol/cli.rb', line 101

def update(argv)
  parser.banner = "Usage: smeagol-update [OPTIONS] [WIKI-DIR]\n"

  #parser.on('-s', '--site', 'Also update site directories, if applicable.') do
  #  options[:site] = true
  #end

  Console.update(*parse(argv))
end