Continue reimplementing missing features.
This commit is contained in:
parent
d3ec76f37a
commit
f5896f6b2d
4 changed files with 71 additions and 50 deletions
|
@ -7,6 +7,7 @@ module Kook
|
||||||
|
|
||||||
class ExistingProject < RuntimeError ; end
|
class ExistingProject < RuntimeError ; end
|
||||||
class MissingProject < RuntimeError ; end
|
class MissingProject < RuntimeError ; end
|
||||||
|
class MissingProjectFile < RuntimeError ; end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -75,9 +76,7 @@ module Kook
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_view project_name, view_name, view_path=nil
|
def add_view project_name, view_name, view_path=nil
|
||||||
Project.validate_name project_name
|
|
||||||
View.validate_name view_name
|
View.validate_name view_name
|
||||||
|
|
||||||
raise MissingProject if not @projects.has_key? project_name
|
raise MissingProject if not @projects.has_key? project_name
|
||||||
|
|
||||||
project_path = @projects[project_name].path
|
project_path = @projects[project_name].path
|
||||||
|
@ -96,23 +95,34 @@ module Kook
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_views project_name
|
def add_command project_name, view_name, command
|
||||||
|
View.validate_name view_name
|
||||||
raise MissingProject if not @projects.has_key? project_name
|
raise MissingProject if not @projects.has_key? project_name
|
||||||
|
|
||||||
# FIXME: return if config['views'][project].nil?
|
@projects[project_name].add_command view_name, command
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_command project_name, view_name, command_idx
|
||||||
|
raise MissingProject if not @projects.has_key? project_name
|
||||||
|
|
||||||
|
@projects[project_name].remove_command view_name, command_idx
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_views project_name
|
||||||
|
raise MissingProject if not @projects.has_key? project_name
|
||||||
|
|
||||||
@projects[project_name].each_view do |view_name,view_data|
|
@projects[project_name].each_view do |view_name,view_data|
|
||||||
puts "%- 24s %s" % [view_name, view_data.path]
|
puts "%- 24s %s" % [view_name, view_data.path]
|
||||||
|
|
||||||
#next if config['commands'][project].nil? or \
|
if view_data.commands.empty?
|
||||||
# config['commands'][project][view].nil?
|
next
|
||||||
|
end
|
||||||
|
|
||||||
#config['commands'][project][view].each_index do |idx|
|
view_data.commands.each_index do |idx|
|
||||||
# puts " % 4d. %s" % [
|
puts "* % 4d. %s" % [idx, view_data.commands[idx]]
|
||||||
# idx,
|
end
|
||||||
# config['commands'][project][view][idx]
|
|
||||||
# ]
|
|
||||||
#end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -132,7 +142,7 @@ module Kook
|
||||||
yaml['projects'].each do |project_name,project_path|
|
yaml['projects'].each do |project_name,project_path|
|
||||||
# pp project_path
|
# pp project_path
|
||||||
#project_path = @config['projects'][project]
|
#project_path = @config['projects'][project]
|
||||||
project_file = kook_file_for project_path
|
project_file = File.join project_path, "Kookfile"
|
||||||
|
|
||||||
STDERR.puts "Loading sub configuration #{project_file}..." if @verbose
|
STDERR.puts "Loading sub configuration #{project_file}..." if @verbose
|
||||||
if File.exist? project_file then
|
if File.exist? project_file then
|
||||||
|
@ -189,12 +199,6 @@ module Kook
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def kook_file_for project_path
|
|
||||||
kook_files = Dir.glob(File.join(project_path, 'Kookfile'))
|
|
||||||
raise MissingProjectFile if kook_files.empty?
|
|
||||||
kook_files.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_yaml
|
def to_yaml
|
||||||
return {
|
return {
|
||||||
'global' => {},
|
'global' => {},
|
||||||
|
|
|
@ -85,7 +85,7 @@ module Kook
|
||||||
desc "edit [PROJECT]", "Open editor on project file"
|
desc "edit [PROJECT]", "Open editor on project file"
|
||||||
def edit project_name=nil
|
def edit project_name=nil
|
||||||
before_filter options
|
before_filter options
|
||||||
project_name ||= options[:project] || @app.current_project
|
project_name ||= @app.current_project
|
||||||
|
|
||||||
@app.edit_project project_name
|
@app.edit_project project_name
|
||||||
end
|
end
|
||||||
|
@ -99,7 +99,7 @@ module Kook
|
||||||
desc "list", "List view for a project"
|
desc "list", "List view for a project"
|
||||||
def list
|
def list
|
||||||
before_filter options
|
before_filter options
|
||||||
project_name = options[:project] || @app.current_project
|
project_name = @app.current_project
|
||||||
|
|
||||||
@app.list_views project_name
|
@app.list_views project_name
|
||||||
end
|
end
|
||||||
|
@ -107,7 +107,7 @@ module Kook
|
||||||
desc "add VIEW", "Register new view"
|
desc "add VIEW", "Register new view"
|
||||||
def add view_name
|
def add view_name
|
||||||
before_filter options
|
before_filter options
|
||||||
project_name = options[:project] || @app.current_project
|
project_name = @app.current_project
|
||||||
|
|
||||||
view_path = options[:directory]
|
view_path = options[:directory]
|
||||||
if view_path.nil? then
|
if view_path.nil? then
|
||||||
|
@ -119,35 +119,33 @@ module Kook
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "rm PROJECT VIEW", "Unregister existing view on project"
|
desc "rm PROJECT VIEW", "Unregister existing view on project"
|
||||||
def rm project, view
|
def rm view_name
|
||||||
# FIXME: validate project existance
|
before_filter options
|
||||||
# FIXME: validate view existance
|
project_name = options[:project] || @app.current_project
|
||||||
config['views'][project].delete view
|
|
||||||
config.save_main
|
@app.remove_view project_name, view_name, view_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: add helper validating project name
|
# FIXME: add helper validating project name
|
||||||
# FIXME: add helper validating vie name for project
|
# FIXME: add helper validating vie name for project
|
||||||
class Command < Thor
|
class Command < Thor
|
||||||
|
include KookHelper
|
||||||
|
|
||||||
desc "add PROJECT VIEW COMMAND", "Add command for view "
|
desc "add PROJECT VIEW COMMAND", "Add command for view "
|
||||||
def add project, view, command
|
def add view_name, command
|
||||||
unless config['commands'].has_key? project then
|
before_filter options
|
||||||
config['commands'][project] = {}
|
project_name = options[:project] || @app.current_project
|
||||||
end
|
|
||||||
if config['commands'][project].nil? then
|
@app.add_command project_name, view_name, command
|
||||||
config['commands'][project] = {}
|
|
||||||
end
|
|
||||||
unless config['commands'][project].has_key? view then
|
|
||||||
config['commands'][project][view] = []
|
|
||||||
end
|
|
||||||
config['commands'][project][view] << command
|
|
||||||
config.save_main
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "rm PROJECT VIEW", "Remove command for view"
|
desc "rm VIEW INDEX", "Remove command for view"
|
||||||
def rm project, view, index
|
def rm view_name, command_index
|
||||||
raise NotImplementedError
|
before_filter options
|
||||||
|
project_name = options[:project] || @app.current_project
|
||||||
|
|
||||||
|
@app.remove_command project_name, view_name, command_index.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,22 @@ module Kook
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_view view_name
|
def remove_view view_name
|
||||||
View.validate_name view_name
|
raise MissingView, view_name if not @views.has_key? view_name
|
||||||
return @view.delete(view_name)
|
return @view.delete(view_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_command view_name, command
|
||||||
|
raise MissingView, view_name if not @views.has_key? view_name
|
||||||
|
@views[view_name].commands << command
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_command view_name, command_idx
|
||||||
|
raise MissingView, view_name if not @views.has_key? view_name
|
||||||
|
@views[view_name].commands.delete_at(command_idx)
|
||||||
|
end
|
||||||
|
|
||||||
def each_view
|
def each_view
|
||||||
pp @views
|
#pp @views
|
||||||
@views.each do |view_name, view_data|
|
@views.each do |view_name, view_data|
|
||||||
yield view_name, view_data
|
yield view_name, view_data
|
||||||
end
|
end
|
||||||
|
@ -70,7 +80,6 @@ module Kook
|
||||||
p.description = project_hash['description']
|
p.description = project_hash['description']
|
||||||
p.path = project_path
|
p.path = project_path
|
||||||
|
|
||||||
#pp project_hash['views']
|
|
||||||
project_hash['views'].each do |view_hash|
|
project_hash['views'].each do |view_hash|
|
||||||
view_data = View.from_hash view_hash
|
view_data = View.from_hash view_hash
|
||||||
p.add_view view_data
|
p.add_view view_data
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
module Kook
|
module Kook
|
||||||
class View
|
class View
|
||||||
attr_reader :name, :path
|
attr_reader :name, :path, :commands
|
||||||
attr_accessor :description
|
attr_accessor :description
|
||||||
VIEW_NAME_MIN_SIZE = 4
|
VIEW_NAME_MIN_SIZE = 4
|
||||||
VIEW_NAME_MAX_SIZE = 12
|
VIEW_NAME_MAX_SIZE = 12
|
||||||
|
@ -10,7 +10,7 @@ module Kook
|
||||||
self.class.validate_name name
|
self.class.validate_name name
|
||||||
@name = name
|
@name = name
|
||||||
@path = path
|
@path = path
|
||||||
@commands = {}
|
@commands = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.validate_name name
|
def self.validate_name name
|
||||||
|
@ -26,14 +26,24 @@ module Kook
|
||||||
return {
|
return {
|
||||||
'view' => @name,
|
'view' => @name,
|
||||||
'path' => @path,
|
'path' => @path,
|
||||||
'commands' => @commands.values
|
'commands' => @commands
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_command command
|
||||||
|
@commands << command
|
||||||
|
end
|
||||||
|
|
||||||
|
def rm_command command_index
|
||||||
|
@command.delete command_index
|
||||||
|
end
|
||||||
|
|
||||||
def self.from_hash view_hash
|
def self.from_hash view_hash
|
||||||
view = View.new view_hash['view'], view_hash['path']
|
view = View.new view_hash['view'], view_hash['path']
|
||||||
# @commands = view_hash['commands']
|
view_hash['commands'].each do |c|
|
||||||
view
|
view.add_command c
|
||||||
|
end
|
||||||
|
return view
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue