Continue reimplementing missing features.

This commit is contained in:
Glenn Y. Rolland 2014-01-03 01:35:43 +01:00
parent d3ec76f37a
commit f5896f6b2d
4 changed files with 71 additions and 50 deletions

View file

@ -7,6 +7,7 @@ module Kook
class ExistingProject < RuntimeError ; end
class MissingProject < RuntimeError ; end
class MissingProjectFile < RuntimeError ; end
def initialize
super
@ -75,9 +76,7 @@ module Kook
end
def add_view project_name, view_name, view_path=nil
Project.validate_name project_name
View.validate_name view_name
raise MissingProject if not @projects.has_key? project_name
project_path = @projects[project_name].path
@ -96,23 +95,34 @@ module Kook
save
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
# 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|
puts "%- 24s %s" % [view_name, view_data.path]
#next if config['commands'][project].nil? or \
# config['commands'][project][view].nil?
if view_data.commands.empty?
next
end
#config['commands'][project][view].each_index do |idx|
# puts " % 4d. %s" % [
# idx,
# config['commands'][project][view][idx]
# ]
#end
view_data.commands.each_index do |idx|
puts "* % 4d. %s" % [idx, view_data.commands[idx]]
end
end
end
@ -132,7 +142,7 @@ module Kook
yaml['projects'].each do |project_name,project_path|
# pp project_path
#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
if File.exist? project_file then
@ -189,12 +199,6 @@ module Kook
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
return {
'global' => {},

View file

@ -85,7 +85,7 @@ module Kook
desc "edit [PROJECT]", "Open editor on project file"
def edit project_name=nil
before_filter options
project_name ||= options[:project] || @app.current_project
project_name ||= @app.current_project
@app.edit_project project_name
end
@ -99,7 +99,7 @@ module Kook
desc "list", "List view for a project"
def list
before_filter options
project_name = options[:project] || @app.current_project
project_name = @app.current_project
@app.list_views project_name
end
@ -107,7 +107,7 @@ module Kook
desc "add VIEW", "Register new view"
def add view_name
before_filter options
project_name = options[:project] || @app.current_project
project_name = @app.current_project
view_path = options[:directory]
if view_path.nil? then
@ -119,35 +119,33 @@ module Kook
end
desc "rm PROJECT VIEW", "Unregister existing view on project"
def rm project, view
# FIXME: validate project existance
# FIXME: validate view existance
config['views'][project].delete view
config.save_main
def rm view_name
before_filter options
project_name = options[:project] || @app.current_project
@app.remove_view project_name, view_name, view_path
end
end
# FIXME: add helper validating project name
# FIXME: add helper validating vie name for project
class Command < Thor
include KookHelper
desc "add PROJECT VIEW COMMAND", "Add command for view "
def add project, view, command
unless config['commands'].has_key? project then
config['commands'][project] = {}
end
if config['commands'][project].nil? then
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
def add view_name, command
before_filter options
project_name = options[:project] || @app.current_project
@app.add_command project_name, view_name, command
end
desc "rm PROJECT VIEW", "Remove command for view"
def rm project, view, index
raise NotImplementedError
desc "rm VIEW INDEX", "Remove command for view"
def rm view_name, command_index
before_filter options
project_name = options[:project] || @app.current_project
@app.remove_command project_name, view_name, command_index.to_i
end
end

View file

@ -45,12 +45,22 @@ module Kook
end
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)
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
pp @views
#pp @views
@views.each do |view_name, view_data|
yield view_name, view_data
end
@ -70,7 +80,6 @@ module Kook
p.description = project_hash['description']
p.path = project_path
#pp project_hash['views']
project_hash['views'].each do |view_hash|
view_data = View.from_hash view_hash
p.add_view view_data

View file

@ -1,7 +1,7 @@
module Kook
class View
attr_reader :name, :path
attr_reader :name, :path, :commands
attr_accessor :description
VIEW_NAME_MIN_SIZE = 4
VIEW_NAME_MAX_SIZE = 12
@ -10,7 +10,7 @@ module Kook
self.class.validate_name name
@name = name
@path = path
@commands = {}
@commands = []
end
def self.validate_name name
@ -26,14 +26,24 @@ module Kook
return {
'view' => @name,
'path' => @path,
'commands' => @commands.values
'commands' => @commands
}
end
def add_command command
@commands << command
end
def rm_command command_index
@command.delete command_index
end
def self.from_hash view_hash
view = View.new view_hash['view'], view_hash['path']
# @commands = view_hash['commands']
view
view_hash['commands'].each do |c|
view.add_command c
end
return view
end
end
end