Class: Softcover::CLI

Inherits:
Thor
  • Object
show all
Includes:
Utils
Defined in:
lib/softcover/cli.rb

Constant Summary

Constants included from Utils

Utils::UNITS

Instance Method Summary collapse

Methods included from Utils

#add_highlight_class!, #article?, #as_size, #book_file_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #filename_or_default, #first_path, #get_filename, #html_extension, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #non_comment_lines, #os_x?, #path, #polytexnic_html, #raw_lines, #reset_current_book!, #rm, #rm_r, #silence, #silence_stream, #source, #template_dir, #tmpify, #unpublish_slug, #write_master_latex_file, #write_pygments_file

Instance Method Details

#buildObject



27
28
29
# File 'lib/softcover/cli.rb', line 27

def build
  Softcover::Commands::Build.all_formats(options)
end

#checkObject



91
92
93
# File 'lib/softcover/cli.rb', line 91

def check
  Softcover::Commands::Check.check_dependencies!
end

#cleanObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/softcover/cli.rb', line 76

def clean
  rm(Dir.glob('*.aux'))
  rm(Dir.glob(File.join('chapters', '*.aux')))
  rm(Dir.glob('*.toc'))
  rm(Dir.glob('*.out'))
  rm(Dir.glob('*.tmp.*'))
  rm(Dir.glob(path('tmp/*.*')))
  rm('.highlight_cache')
  rm('tmp/.highlight_cache')
end

#configObject



251
252
253
254
255
# File 'lib/softcover/cli.rb', line 251

def config
  require "softcover/config"
  puts "Reading contents of #{Softcover::Config.path}:"
  Softcover::Config.read
end

#deployObject



204
205
206
# File 'lib/softcover/cli.rb', line 204

def deploy
  Softcover::Commands::Deployment.deploy!
end

#loginObject



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

def 
  puts "Logging in."

  logged_in = false
  while not logged_in do
    email = ask "Email:"
    password = ask_without_echo "Password (won't be shown):"
    unless logged_in = Softcover::Commands::Auth.(email, password)
      puts "Invalid login, please try again."
    end
  end
  puts "Welcome back, #{email}!"
end

#logoutObject



139
140
141
# File 'lib/softcover/cli.rb', line 139

def logout
  Softcover::Commands::Auth.logout
end

#new(n) ⇒ Object



223
224
225
# File 'lib/softcover/cli.rb', line 223

def new(n)
  Softcover::Commands::Generator.generate_file_tree(n, options)
end

#openObject



232
233
234
# File 'lib/softcover/cli.rb', line 232

def open
  Softcover::Commands::Opener.open!
end

#publishObject



154
155
156
157
158
159
160
161
# File 'lib/softcover/cli.rb', line 154

def publish
  require 'softcover/commands/publisher'

  invoke :login unless logged_in?

  puts "Publishing..." unless options[:silent]
  Softcover::Commands::Publisher.publish!(options)
end

#serverObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/softcover/cli.rb', line 104

def server
  if Softcover::BookManifest::valid_directory?
    if options[:pdf]
      port = options[:port] || 5000
    else
      port = options[:port] || 4000
    end
    Softcover::Commands::Server.run port, options[:bind],
                                    options[:pdf], options[:overfull]
  else
    puts 'Not in a valid book directory.'
    exit 1
  end
end

#unpublishObject



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/softcover/cli.rb', line 187

def unpublish
  require 'softcover/commands/publisher'

  invoke :login unless logged_in?
  slug = options[:slug] || unpublish_slug
  if options[:force] || ask("Type '#{slug}' to unpublish:") == slug
    puts "Unpublishing..." unless options[:silent]
    Softcover::Commands::Publisher.unpublish!(slug)
  else
    puts "Canceled."
  end
end

#versionObject



12
13
14
15
16
# File 'lib/softcover/cli.rb', line 12

def version
  require 'softcover/version'
  puts "Softcover #{Softcover::VERSION}"
  exit 0
end