Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two command line options: --verbose and --target #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions bin/generate_docs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,44 @@
require 'lock_file'
require 'docs_generator'
require 'git_manager'
require 'fileutils'
require 'optparse'

options = {}

OptionParser.new do |opts|
opts.banner = "Usage: bin/generate_docs.rb [options]"

opts.on("-v", "--verbose", "Run verbosely") do |v|
options[:verbose] = v
end

opts.on(
"-tTARGET",
"--target=TARGET",
"Target directory where to checkout the code, defaults to HOME"
) do |t|
options[:target] = t
end
end.parse!

options[:verbose] = false if options[:verbose].nil?
options[:target] ||= Dir.home
options[:target].gsub!(/\/$/, '')

unless Dir.exists?(options[:target])
FileUtils.mkdir(options[:target])
end

LockFile.acquiring('docs_generation.lock') do
git_manager = GitManager.new(Dir.home)
git_manager = GitManager.new(options[:target], verbose: options[:verbose])
git_manager.update_master

generator = DocsGenerator.new(Dir.home, git_manager)
generator = DocsGenerator.new(
options[:target],
git_manager,
verbose: options[:verbose]
)

generator.generate
end
12 changes: 9 additions & 3 deletions lib/docs_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ class DocsGenerator
#
# @param basedir [String]
# @param git_manager [GitManager]
def initialize(basedir, git_manager=GitManager.new(basedir))
def initialize(basedir, git_manager = GitManager.new(basedir), verbose: false)
@basedir = File.expand_path(basedir)
@git_manager = git_manager
@verbose = verbose
end

def generate
Expand Down Expand Up @@ -98,7 +99,7 @@ def generate_docs_for_release?(tag)
def generate_docs_for_release(tag)
git_manager.checkout(tag)

generator = Generators::Release.new(tag, tag)
generator = Generators::Release.new(tag, tag, verbose: @verbose)
generator.generate

DocsCompressor.new(generator.api_output).compress
Expand All @@ -109,7 +110,12 @@ def generate_docs_for_release(tag)
end

def generate_edge_docs
generator = Generators::Master.new(git_manager.short_sha1, 'master')
generator = Generators::Master.new(
git_manager.short_sha1,
'master',
verbose: @verbose
)

generator.generate

DocsCompressor.new(generator.api_output).compress
Expand Down
9 changes: 7 additions & 2 deletions lib/generators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ class Base

# @param target [String] A Git reference like 'v4.2.0' or a SHA1
# @param basedir [String] A directory in which target has been checked out
def initialize(target, basedir)
def initialize(target, basedir, verbose: false)
@target = target
@basedir = File.expand_path(basedir)
@verbose = verbose
end

def dev_null_unless_verbose
@verbose ? "" : " > /dev/null"
end

# Generates the documentation for target within basedir.
Expand Down Expand Up @@ -72,7 +77,7 @@ def env_as_assigns(env)
# @param command [String]
# @param env [Hash{String => String}]
def run(command, env={})
command = "rvm #{ruby_version} do #{command} >/dev/null"
command = "rvm #{ruby_version} do #{command}#{dev_null_unless_verbose}"
log "#{env_as_assigns(env)} #{command}"
system(env, command)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Generators
class Release < Base
include Config::Release

def initialize(tag, basedir)
super(tag, basedir)
def initialize(tag, basedir, verbose: false)
super(tag, basedir, verbose: verbose)
@version_number = VersionNumber.new(tag)
end

Expand Down
15 changes: 10 additions & 5 deletions lib/git_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class GitManager

attr_reader :basedir

def initialize(basedir)
def initialize(basedir, verbose: false)
@basedir = File.expand_path(basedir)
@verbose = verbose
end

def q_unless_verbose
@verbose ? "" : "-q"
end

def remote_rails_url
Expand All @@ -18,7 +23,7 @@ def update_master
Dir.chdir(basedir) do
unless Dir.exist?('master')
log "cloning master into #{basedir}/master"
system "git clone -q #{remote_rails_url} master"
system "git clone #{q_unless_verbose} #{remote_rails_url} master"
end

Dir.chdir('master') do
Expand All @@ -29,18 +34,18 @@ def update_master
# does not change BUNDLED WITH is left as is, even if versions differ,
# but since docs generation is automated better play safe.
system 'git checkout Gemfile.lock'
system 'git pull -q'
system "git pull #{q_unless_verbose}"
end
end
end

def checkout(tag)
Dir.chdir(basedir) do
log "checking out tag #{tag}"
system "git clone -q #{remote_rails_url} #{tag}"
system "git clone #{q_unless_verbose} #{remote_rails_url} #{tag}"

Dir.chdir(tag) do
system "git checkout -q #{tag}"
system "git checkout #{q_unless_verbose} #{tag}"
end
end
end
Expand Down