Module: Yac
- Extended by:
- Yac
- Includes:
- Format
- Included in:
- Yac
- Defined in:
- lib/yac.rb
Constant Summary
collapse
- VERSION =
'1.4.5'
- YACRC =
File.join("#{ENV['HOME']}",".yacrc")
- CONFIG =
YAML.load_file( File.exist?(YACRC) ? YACRC :
File.join(File.dirname(__FILE__), "..","resources","yacrc"))
Instance Method Summary
collapse
Methods included from Format
#Error, #colorful, #edit_text, #empha, #format_text, #handle_file
Instance Method Details
#add(args) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/yac.rb', line 81
def add(args)
file = add_file(args,'.yac')
if file && confirm("You Are Adding #{file}")
edit_text(file)
Git.add(file)
end
end
|
#edit(args) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/yac.rb', line 89
def edit(args)
file = search_name(args,"Edit")
if file
handle_file(file,'edit')
Git.edit(file)
end
end
|
#help ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/yac.rb', line 104
def help
puts <<-DOC.gsub(/^(\s*)/,'').gsub(/^\|(\s*)/,'\1')
Usage:
| yac -i <keyword> init
| yac -S <keyword> search
| yac -u <keyword> update
| yac -p <keyword> push
| yac -l <keyword> log
| yac -a <keyword> add
| yac -e <keyword> edit
| yac -s <keyword> shell
| yac -r <keyword> delete<rm>
| yac -m <keyword> rename<mv>
| yac -h Show this help
| yac -v Show Version
| yac <keyword> Show
DOC
end
|
#init ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/yac.rb', line 59
def init
{"main" => @main_path,"private" => @pri_path}.each do |name,path|
if File.exist?(path)
colorful("#{name} repository has already initialized.","notice")
elsif CONFIG["#{name}"] && CONFIG["#{name}"]['clone-from']
colorful("Initialize #{name} repository from #{CONFIG[name]['clone-from']}","notice")
Git.clone(CONFIG["#{name}"]['clone-from'],path)
end
end
end
|
#mv(args) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/yac.rb', line 133
def mv(args)
(colorful("Usage:\nyac mv [orign_name] [new_name]","warn");exit) unless args.size == 2
file = search_name(args[0],"Rename")
new_filename = (args[1] !~ /\/$/) ? args[1] : args[1] + file.match(/[^\/]*$/).to_s.sub(/\.\w*$/,'')
new_filename = '@' + new_filename if file =~ /^#{@main_path}/
new_name = add_file(new_filename,'.yac')
if new_name && confirm("You Are Renaming #{file} To #{new_name}")
Git.mv(file,new_name)
end
end
|
#new(args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/yac.rb', line 39
def new(args)
operate, target = args.shift.to_s , args.join(' ').to_s
case operate
when "-i" then init
when "-S" then search target
when "-u" then update target
when "-p" then push target
when "-l" then log target
when "-a" then add target
when "-e" then edit target
when "-s" then shell target
when "-r" then rm target
when "-m" then mv args
when /^(help|-h|yac|--help)$/ then help
when "-v" then colorful("Yac Version: #{Yac::VERSION}",'notice')
else show operate + ' ' + target
end
end
|
#rm(args) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/yac.rb', line 97
def rm(args)
file = search_name(args,"Remove")
if file && confirm("You Are Removing #{file}.")
Git.rm(file)
end
end
|
#search(args) ⇒ Object
77
78
79
|
# File 'lib/yac.rb', line 77
def search(args)
search_content(args)
end
|
#shell(args) ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'lib/yac.rb', line 123
def shell(args)
if args.to_s =~ /main/
colorful(" Welcome To The Main Yac Repository","notice")
system("cd '#{@main_path}'; sh")
else
colorful(" Welcome To The Private Yac Repository","notice")
system("cd '#{@pri_path}'; sh")
end
end
|
#show(args) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/yac.rb', line 70
def show(args)
loop do
file = search_name(args,"Show")
file ? handle_file(file) : break
end
end
|