Module: Yuzu::Command

Defined in:
lib/yuzu/command.rb,
lib/yuzu/argparse.rb,
lib/yuzu/commands/base.rb,
lib/yuzu/commands/help.rb,
lib/yuzu/commands/stage.rb,
lib/yuzu/commands/watch.rb,
lib/yuzu/commands/create.rb,
lib/yuzu/commands/preview.rb,
lib/yuzu/commands/publish.rb,
lib/yuzu/commands/generate.rb

Defined Under Namespace

Classes: ArgParser, Base, CommandFailed, ConfiglessCommand, Create, Generate, Help, InvalidCommand, Preview, PublicationCommand, Publish, Stage, Watch

Constant Summary collapse

HELP_MESSAGE =
%Q{
This is yuzu, a blog-aware, static-website generator and publisher that converts
a folder of text files and images into an HTML5 website.

Typical Usage

  yuzu [command] [options] [files]

Available Commands

  help                  # Show this help page.
  help [command]        # Help about the particular command.
  create                # Creates a new yuzu project in the current folder.
  preview               # Updates files in the preview folder.
  publish               # Publishes files to the currently selected remote server.
  stage                 # Updates files in the staging folder.
  generate              # Generate new content like posts and thumbnails.
}

Class Method Summary collapse

Class Method Details

.execute(command_class, method, args, parsed_options) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/yuzu/command.rb', line 50

def self.execute(command_class, method, args, parsed_options)
  if command_class.requires_config?
    config_hash = load_config

    config = \
    Yuzu::Core::Config.new(
      config_hash,
      command_class.service_override,
      parsed_options
    )

    command_instance = command_class.new(args, config)
    command_instance.send(method)

  else
    command_instance = command_class.new(args)
    command_instance.send(method)
  end
rescue => e
  $stderr.puts e.message
  $stderr.puts e.backtrace
  raise CommandFailed
end

.load_configObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/yuzu/command.rb', line 74

def self.load_config
  config_location = locate_config

  if config_location.nil?
    $stderr.puts CONFIG_NOT_FOUND_MESSAGE
    Process.exit!(false)
  end

  YAML.load_file(config_location)
end

.locate_configObject



85
86
87
88
89
90
91
92
# File 'lib/yuzu/command.rb', line 85

def self.locate_config
  possible_config_locations.each do |path|
    if File.exists?(path)
      return path
    end
  end
  return nil
end

.parse(command_str) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/yuzu/command.rb', line 41

def self.parse(command_str)
  command, method = command_str.split(':').collect {|part| part.strip}
  method = method.nil? ? :index : method.to_sym

  return Yuzu::Command.const_get(command.capitalize), method
rescue
  raise InvalidCommand
end

.possible_config_locationsObject



94
95
96
97
98
99
# File 'lib/yuzu/command.rb', line 94

def self.possible_config_locations
  [
    File.join(Dir.pwd, "yuzu.yml"),
    File.join(Dir.pwd, "config", "yuzu.yml")
  ]
end

.run(command_str, args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/yuzu/command.rb', line 20

def self.run(command_str, args)
  start = Time.now

  options = ArgParser.parse(args)

  if command_str.nil?
    exit
  end

  command_class, method = parse(command_str.downcase)
  execute(command_class, method, args[1, args.length] || [], options)

  stop = Time.now
  delta = stop - start
  if options.output == :verbose
    $stderr.puts "Yuzu completed in #{delta} seconds."
  else
    $stderr.puts
  end
end