lib/hackpad/cli/client.rb in hackpad-cli-0.1.2 vs lib/hackpad/cli/client.rb in hackpad-cli-0.1.3
- old
+ new
@@ -1,8 +1,9 @@
require 'paint'
require_relative 'config'
+require_relative 'workspace'
require_relative 'api'
require_relative 'store'
require_relative 'pad'
require_relative 'padlist'
@@ -13,19 +14,23 @@
attr_reader :config
def initialize(options, input = STDIN, output = STDOUT)
@output = output
@input = input
- @options = options
- @config = Config.new @options, input, output
- Store.prepare @config
- Api.prepare @config
- if @options[:plain] == true || @config.use_colors == false
+ @config = Config.new options, @input, @output
+ if options[:plain] == true || @config.use_colors == false
Paint.mode = 0
end
+ @workspace = Workspace.new({ basedir: File.join(@config.basedir, @config.workspace), name: @config.workspace }, @input, @output)
+ Store.prepare @config, @workspace
+ Api.prepare @workspace
end
+ def add
+ @workspace.clone.create
+ end
+
def workspaces
@config.workspaces.each do |s|
if s.name == @config.workspace
s.name = "> #{s.name}"
end
@@ -36,11 +41,11 @@
def default
@config.change_default
end
def stats
- table 'Site', Paint[@config.site, :blue]
+ table 'Site', Paint[@workspace.site, :blue]
table 'Cached Pads', Store.count_pads
table 'Last Refresh', Store.last_refresh || 'not refreshed yet'
end
def search(term, start = 0)
@@ -50,11 +55,11 @@
@output.puts " #{extract a['snippet']}"
end
end
def list
- @output.puts Padlist.get_list(@options['refresh']).map { |pad|
+ @output.puts Padlist.get_list(@config.refresh).map { |pad|
padline pad
}
end
def getnew
@@ -72,11 +77,11 @@
def info(id)
pad = Pad.new id
pad.load 'txt'
table 'Id', Paint[id, :bold]
table 'Title', Paint[pad.title, :yellow]
- table 'URI', "#{@config.site}/#{id}"
+ table 'URI', "#{@workspace.site}/#{id}"
table 'Chars', "#{pad.chars}"
table 'Lines', "#{pad.lines}"
table 'Guest Policy', "#{pad.guest_policy}"
table 'Moderated', "#{pad.moderated}"
table 'Cached', "#{pad.cached_at || 'unknown'}"
@@ -89,11 +94,11 @@
end
private
def padline(pad)
- "#{(@config.site + '/') if @options[:urls]}#{pad.id} - #{pad.title}"
+ "#{(@workspace.site + '/') if @config.urls}#{pad.id} - #{pad.title}"
end
def unescape(s)
CGI.unescapeHTML s
end
@@ -105,10 +110,10 @@
def table(key, value)
@output.printf "%-20s %s\n", key, value
end
def id_or_url(id)
- "#{(@config.site + '/') if @options[:urls]}#{Paint[id, :bold]}"
+ "#{(@workspace.site + '/') if @config.urls}#{Paint[id, :bold]}"
end
end
end
end