module Resuby::CLI

Constants

GENERATE_BANNER
INIT_BANNER
RESUBY_BANNER

Public Class Methods

execute() click to toggle source
# File lib/resuby/cli/cli.rb, line 51
def self.execute
  case @subcommand
  when 'generate'
    Resuby::CLI.generate
  when 'init'
    Resuby::CLI.init
  else
    Optimist::die "Unknonwn subcommand #{@subcommand.inspect}"
  end
end
generate() click to toggle source
# File lib/resuby/cli/exe.rb, line 2
def self.generate
  resume = Resuby::Resume.new
  ext =
    if @opts[:yaml]
      '.yaml'
    elsif @opts[:json]
      '.json'
    else
      nil
    end
  resume.read_source(@opts[:data], ext)
  resume.save_resume(@opts[:output])
  resume.compile_styles
end
global_options() click to toggle source
# File lib/resuby/cli/cli.rb, line 17
def self.global_options
  @global_opts = Optimist::options do
    banner Resuby::CLI::RESUBY_BANNER
    version "resuby version #{Resuby::VERSION}"
    stop_on %w(generate init)
  end
end
init() click to toggle source
# File lib/resuby/cli/exe.rb, line 17
def self.init
  unless @opts[:force]
    if File.file?(@opts[:output]) && File.size?(@opts[:output])
      print "#{@opts[:output]} already exists, would you like to proceed (Y/N)? "
      proceed = gets.chomp
      unless proceed == 'Y'
        warn 'Aborted!'
        exit 1
      end
    end
  end
  template = {
    'name'=> 'Bob Smith',
    'contact'=> [
      '(321) 321-4321',
      'bob.smith@resuby.com',
    ],
    'profile'=> 'This section is optional, but it is a good place to write a short paragraph about yourself.',
    'experience'=> [
      {
        'title'=> 'Position 1',
        'subtitle'=> 'Company 1',
        'desc'=> 'Jan 2018 - present',
        'data'=> [
          'Responsibility/accomplishment 1',
          'Responsibility/accomplishment 2',
          'Responsibility/accomplishment 3',
        ],
      },{
        'title'=> 'Position 2',
        'subtitle'=> 'Company 2',
        'desc'=> 'Jan 2017 - Jan 2018',
        'data'=> [
          'Responsibility/accomplishment 1',
          'Responsibility/accomplishment 2',
          'Responsibility/accomplishment 3',
        ],
      }
    ],
    'projects'=> [
      {
        'title'=> 'Project 1',
        'subtitle'=> 'Company 1',
        'desc'=> 'Aug 2018 - present',
        'data'=> [
          'Responsibility/accomplishment 1',
          'Responsibility/accomplishment 2',
          'Responsibility/accomplishment 3',
        ]
      },{
        'title'=> 'Project 2',
        'subtitle'=> 'Company 2',
        'desc'=> 'Mar 2017 - Jan 2018',
        'data'=> [
          'Responsibility/accomplishment 1',
          'Responsibility/accomplishment 2',
          'Responsibility/accomplishment 3',
        ],
      }
    ],
    'education'=> [
      {
        'title' => 'Some University',
        'desc' => 'Aug 2010 - May 2014',
        'data' => [
          'Degree, GPA',
        ],
      }
    ],
    'skills'=> [
      {
        'desc' => 'Languages',
        'data' => [
          'Ruby, Python',
          'HTML, CSS, Javascript',
        ],
      },{
        'desc' => 'Tools',
        'data' => [
          'Tool 1, Tool 2',
          'Tool 3, Tool 4',
        ],
      },
    ],
  }
  puts "Storing template at #{@opts[:output]}"
  if @opts[:yaml]
    File.open(@opts[:output], 'w') { |f| f.puts template.to_yaml }
  elsif @opts[:json]
    File.open(@opts[:output], 'w') { |f| f.puts JSON.pretty_generate(template) }
  else
    puts 'Template format is not supported'
    exit 1
  end
end
options() click to toggle source
# File lib/resuby/cli/cli.rb, line 10
def self.options
  Resuby::CLI.global_options
  @subcommand = ARGV.shift
  Resuby::CLI.subcommand_options
  Resuby::CLI.execute
end
run() click to toggle source
# File lib/resuby/cli/cli.rb, line 6
def self.run
  Resuby::CLI.options
end
subcommand_options() click to toggle source
# File lib/resuby/cli/cli.rb, line 25
def self.subcommand_options
  case @subcommand
  when 'generate'
    @opts = Optimist::options do
      banner Resuby::CLI::GENERATE_BANNER
      opt :data, 'Path to file containing data for the resume', default: File.join(Dir.pwd, 'resume.yaml')
      opt :json, 'Read in data file as a JSON formatted file'
      opt :output, 'Output file for generated HTML', default: File.join(Dir.pwd, 'resume.html')
      opt :yaml, 'Read in data file as a YAML formatted file'
    end
    Optimist::die 'Data file connot be JSON and YAML' if @opts[:json] && @opts[:yaml]
  when 'init'
    @opts = Optimist::options do
      banner Resuby::CLI::INIT_BANNER
      opt :force, 'Force overwrite of data file if already present'
      opt :json, 'Outputs data template in JSON format'
      opt :output, 'Path to file where data template should be placed', required: true, type: :string
      opt :yaml, 'Outputs data template in YAML format'
    end
    Optimist::die 'Cannot output two different formats at the same time' if @opts[:json] && @opts[:yaml]
    Optimist::die 'You must specify an output format' unless @opts[:json] || @opts[:yaml]
  else
    Optimist::die "Unknonwn subcommand #{@subcommand.inspect}"
  end
end