Added edition support.

This commit is contained in:
Glenn Y. Rolland 2014-01-03 00:53:49 +01:00
parent 4cb5238065
commit 90576fb2b4
2 changed files with 25 additions and 16 deletions

View file

@ -41,6 +41,13 @@ module Kook
save save
end end
def edit_project project_name
raise MissingProject if not @projects.has_key? project_name
project_config_path = File.join @projects[project_name].path, "Kookfile"
system "%s %s" % [ENV['EDITOR'], project_config_path]
end
def remove_project project_name def remove_project project_name
raise MissingProject if not @projects.has_key? project_name raise MissingProject if not @projects.has_key? project_name
@projects.delete project_name @projects.delete project_name

View file

@ -34,6 +34,12 @@ module Kook
default: nil, default: nil,
aliases: '-p', aliases: '-p',
desc: 'Target project' desc: 'Target project'
class_option :directory,
type: :string,
default: nil,
aliases: '-d',
desc: 'Target directory'
end end
end end
end end
@ -55,11 +61,10 @@ module Kook
@app.list_projects @app.list_projects
end end
option :path
desc "add PROJECT", "Register new project" desc "add PROJECT", "Register new project"
def add project_name, project_path=nil def add project_name
before_filter options before_filter options
project_path = options[:path] project_path = options[:directory]
if project_path.nil? then if project_path.nil? then
project_path = Dir.pwd project_path = Dir.pwd
@ -77,14 +82,12 @@ module Kook
say "Project #{project} unregistered." say "Project #{project} unregistered."
end end
desc "edit PROJECT", "Open editor on project file" desc "edit [PROJECT]", "Open editor on project file"
def edit project def edit project_name=nil
if config['projects'].has_key? project then before_filter options
project_config_path = File.join CONFIG_DIR, "Kookfile" project_name ||= options[:project] || @app.current_project
system "%s %s" % [ENV['EDITOR'], project_config_path]
else @app.edit_project project_name
raise "Project #{project} not found"
end
end end
# TODO: editcopy project to another name + base path # TODO: editcopy project to another name + base path
# TODO: copy project to another name + base path # TODO: copy project to another name + base path
@ -94,20 +97,19 @@ module Kook
include KookHelper include KookHelper
desc "list", "List view for a project" desc "list", "List view for a project"
def list project_name=nil def list
before_filter options before_filter options
project_name ||= @app.current_project project_name = options[:project] || @app.current_project
@app.list_views project_name @app.list_views project_name
end end
desc "add VIEW", "Register new view" desc "add VIEW", "Register new view"
option :path
def add view_name def add view_name
before_filter options before_filter options
project_name ||= @app.current_project project_name = options[:project] || @app.current_project
view_path = options[:path] view_path = options[:directory]
if view_path.nil? then if view_path.nil? then
view_path = Dir.pwd view_path = Dir.pwd
end end