my_help 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/Gemfile.lock +1 -1
  4. data/README.org +3 -3
  5. data/lib/my_help/my_help_controll.rb +20 -15
  6. data/lib/my_help/version.rb +1 -1
  7. data/{before_gli/lib/templates/emacs_help.org → lib/templates/emacs.org} +0 -0
  8. data/{before_gli/lib/templates/template_help.org → lib/templates/help_template.org} +0 -0
  9. data/{before_gli/lib/templates/org_help.org → lib/templates/org.org} +0 -0
  10. data/{before_gli/lib/templates/my_todo.org → lib/templates/todo.org} +2 -2
  11. metadata +6 -38
  12. data/before_gli/Dockerfile.template +0 -13
  13. data/before_gli/Gemfile +0 -5
  14. data/before_gli/Gemfile.lock +0 -63
  15. data/before_gli/bin/console +0 -14
  16. data/before_gli/bin/setup +0 -8
  17. data/before_gli/exe/e_h +0 -4
  18. data/before_gli/exe/emacs_help +0 -4
  19. data/before_gli/exe/m_t +0 -4
  20. data/before_gli/exe/my_help +0 -6
  21. data/before_gli/exe/my_todo +0 -4
  22. data/before_gli/exe/o_h +0 -4
  23. data/before_gli/exe/org_help +0 -4
  24. data/before_gli/lib/emacs_help.rb +0 -137
  25. data/before_gli/lib/my_help/my_help_controll.rb +0 -134
  26. data/before_gli/lib/my_help/org2yml.rb +0 -47
  27. data/before_gli/lib/my_help/specific_help.rb +0 -2
  28. data/before_gli/lib/my_help/test.rb +0 -29
  29. data/before_gli/lib/my_help/version.rb +0 -3
  30. data/before_gli/lib/my_help/yml2org.rb +0 -34
  31. data/before_gli/lib/my_help.rb +0 -204
  32. data/before_gli/lib/my_help_new.rb +0 -54
  33. data/before_gli/lib/my_help_thor.rb +0 -170
  34. data/before_gli/lib/specific_help.rb +0 -172
  35. data/before_gli/lib/specific_help_bu.rb +0 -233
  36. data/before_gli/lib/specific_help_opt.rb +0 -71
  37. data/before_gli/lib/specific_help_thor.rb +0 -172
  38. data/before_gli/make_docker.sh +0 -5
  39. data/before_gli/my_help.gemspec +0 -34
  40. data/lib/templates/emacs_help.org +0 -50
  41. data/lib/templates/my_todo.org +0 -11
  42. data/lib/templates/org_help.org +0 -64
  43. data/lib/templates/template_help.org +0 -8
@@ -1,47 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'yaml'
3
- require 'pp'
4
-
5
- class OrgToYaml
6
- attr_accessor :help_cont
7
-
8
- def initialize(file)
9
- @help_cont = {} #{ head: [File.basename(file, '.org')] }
10
- @head_sym = nil
11
- @conts = ''
12
- org_to_yaml(File.readlines(file))
13
- end
14
-
15
- def make_options(line)
16
- head, desc = line.split(':')
17
- desc ||= head.to_s
18
- short = "-#{head[0]}"
19
- { short: short, long: "--#{head}", desc: desc }
20
- end
21
-
22
- def next_cont(head)
23
- @help_cont[@head_sym][:cont] = @conts if @head_sym
24
- return if head == 'EOF'
25
- @conts = ''
26
- @head_sym = head.to_sym
27
- @help_cont[@head_sym] = {
28
- opts: make_options(head), title: head, cont: ''
29
- }
30
- end
31
-
32
- def org_to_yaml(lines)
33
- lines.each do |line|
34
- if m = line.match(/^\* (.+)/)
35
- next_cont m[1]
36
- else
37
- @conts << line
38
- end
39
- end
40
- next_cont 'EOF'
41
- end
42
- end
43
-
44
- if $PROGRAM_NAME == __FILE__
45
- helps = OrgToYaml.new(ARGV[0])
46
- pp helps.help_cont
47
- end
@@ -1,2 +0,0 @@
1
- module SpecificHelp
2
- class
@@ -1,29 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'yaml'
3
- require 'coderay'
4
- require 'pp'
5
- yaml =<<EOF
6
- :file:
7
- :opts:
8
- :short: "-f"
9
- :long: "--ファイル"
10
- :desc: File操作
11
- :title: ファイル操作file
12
- :cont:
13
- - c-x c-f, Find file, ファイルを開く
14
- - c-x c-s, Save file, ファイルを保存
15
- - c-x c-w, Write file NAME, ファイルを別名で書き込む
16
- EOF
17
- pp data=YAML.load(yaml)
18
- print YAML.dump(data)
19
-
20
-
21
- data0={:new_item=>
22
- {:opts=>{:short=>"-n", :long=>"--new_item", :desc=>"new item"},
23
- :title=>"new_item",
24
- :cont=>
25
- ["new cont"]}}
26
-
27
- print YAML.dump(data0)
28
- puts CodeRay.scan(YAML.dump(data0),:yaml).term
29
- puts CodeRay.scan(yaml,:yaml).term
@@ -1,3 +0,0 @@
1
- module MyHelp
2
- VERSION = "0.6.2"
3
- end
@@ -1,34 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "yaml"
3
-
4
- class YmlToOrg
5
- attr_accessor :contents
6
-
7
- def initialize(file)
8
- @contents = ''
9
- cont = ''
10
- if file.kind_of?(String)
11
- cont = YAML.load(File.read(file))
12
- elsif file.kind_of?(Hash)
13
- cont = file
14
- end
15
- yml_to_org(cont)
16
- end
17
-
18
- def plain_element(key, cont)
19
- @contents << cont[:cont].join("\n")+"\n" if cont.include?(:cont)
20
- end
21
-
22
- def yml_to_org(help_cont)
23
- pp help_cont
24
- @contents << "#+STARTUP: indent nolineimages\n" # nofold
25
- help_cont.each_pair do |key, cont|
26
- @contents << "* #{key.to_s}\n"
27
- plain_element(key, cont)
28
- end
29
- end
30
- end
31
-
32
- if __FILE__ == $0
33
- print YmlToOrg.new(ARGV[0]).contents
34
- end
@@ -1,204 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "optparse"
3
- require "yaml"
4
- require 'my_help/org2yml'
5
- require 'my_help/yml2org'
6
- require "fileutils"
7
- require "my_help/version"
8
- require "systemu"
9
- require "colorize"
10
-
11
- module MyHelp
12
- class Command
13
-
14
- def self.run(argv=[])
15
- new(argv).execute
16
- end
17
-
18
- def initialize(argv=[])
19
- @argv = argv
20
- @template_dir = File.expand_path("../../lib/templates", __FILE__)
21
- @exe_dir = File.expand_path("../../exe", __FILE__)
22
- @local_help_dir = File.join(ENV['HOME'],'.my_help')
23
- @system_inst_dir = RbConfig::CONFIG['bindir']
24
- set_help_dir_if_not_exists
25
- end
26
-
27
- def set_help_dir_if_not_exists
28
- return if File::exists?(@local_help_dir)
29
- FileUtils.mkdir_p(@local_help_dir, :verbose=>true)
30
- Dir.entries(@template_dir).each{|file|
31
- next if file=='template_help.org'
32
- file_path=File.join(@local_help_dir,file)
33
- next if File::exists?(file_path)
34
- FileUtils.cp((File.join(@template_dir,file)),@local_help_dir,:verbose=>true)
35
- }
36
- end
37
-
38
- def execute
39
- @argv << '--help' if @argv.size==0
40
- command_parser = OptionParser.new do |opt|
41
- opt.on('-v', '--version','show program Version.') { |v|
42
- opt.version = MyHelp::VERSION
43
- puts opt.ver
44
- }
45
- opt.on('-l', '--list', 'list specific helps'){list_helps}
46
- opt.on('-e NAME', '--edit NAME', 'edit NAME help(eg test_help)'){|file| edit_help(file)}
47
- opt.on('-i NAME', '--init NAME', 'initialize NAME help(eq test_help)'){|file| init_help(file)}
48
- opt.on('-m', '--make', 'make executables for all helps'){make_help}
49
- opt.on('-c', '--clean', 'clean up exe dir.'){clean_exe_dir}
50
- opt.on('-y', '--yml2org [FILE]', 'convert FILE from yaml to org format'){|file| yml2org(file)}
51
- opt.on('--install_local','install local after edit helps'){install_local}
52
- opt.on('--delete NAME','delete NAME help'){|file| delete_help(file)}
53
- end
54
- begin
55
- command_parser.parse!(@argv)
56
- rescue=> eval
57
- p eval
58
- end
59
- exit
60
- end
61
-
62
- def yml2org(file)
63
- p target = File.join(@local_help_dir,file+'.yml')
64
- cont = YmlToOrg.new(target).contents
65
- dump = file+'.org'
66
- File.open(dump, 'w'){|file| file.print cont }
67
- delete_help(file)
68
- end
69
-
70
- def delete_help(file)
71
- del_files=[]
72
- del_files << File.join(@local_help_dir,file+'.org')
73
- exe_dir=File.join(File.expand_path('../..',@template_dir),'exe')
74
- exe_0_dir= @exe_dir
75
- del_files << File.join(exe_dir,file)
76
- del_files << File.join(exe_0_dir,file)
77
- del_files << File.join(exe_dir,short_name(file))
78
- del_files << File.join(exe_0_dir,short_name(file))
79
- del_files.each do |file|
80
- print "Are you sure to delete "+file.blue+"?[Ynq] ".red
81
- case gets.chomp
82
- when 'Y'
83
- begin
84
- FileUtils.rm(file,:verbose=>true)
85
- rescue => error
86
- puts error.to_s.red
87
- end
88
- when 'n' ; next
89
- when 'q' ; exit
90
- end
91
- end
92
- end
93
-
94
- def install_local
95
- local_help_entries.each do |file|
96
- title = file.split('.')[0]
97
- [title, short_name(title)].each do |name|
98
- source = File.join(@exe_dir, name)
99
- target = File.join(@system_inst_dir, name)
100
- FileUtils.cp(source, target, verbose: true)
101
- end
102
- end
103
- end
104
-
105
- def short_name(file)
106
- file_name=file.split('_')
107
- return file_name[0][0]+"_"+file_name[1][0]
108
- end
109
-
110
- def make_help
111
- local_help_entries.each{|file|
112
- title = file.split('.')[0]
113
- exe_cont=<<"EOS"
114
- #!/usr/bin/env ruby
115
- require 'specific_help'
116
- help_file = File.join(ENV['HOME'],'.my_help','#{file}')
117
- SpecificHelp::Command.run(help_file, ARGV)
118
- EOS
119
- [title, short_name(title)].each do |name|
120
- p target=File.join(@exe_dir, name)
121
- File.open(target,'w'){|file| file.print exe_cont}
122
- FileUtils.chmod('a+x', target, :verbose => true)
123
- end
124
- }
125
- install_local
126
- end
127
-
128
- def clean_exe_dir
129
- local_help_entries.each{|file|
130
- next if ['emacs_help.org', 'my_help.org',
131
- 'my_todo.org', 'org_help.org'].include?(file)
132
- file = File.basename(file,'.org')
133
- [file, short_name(file)].each{|name|
134
- p target=File.join(@exe_dir, name)
135
- begin
136
- FileUtils::Verbose.rm(target)
137
- rescue=> eval
138
- puts eval.to_s.red
139
- end
140
- }
141
- }
142
- end
143
-
144
- def init_help(file)
145
- p target_help=File.join(@local_help_dir,file+'.org')
146
- if File::exists?(target_help)
147
- puts "File exists. --delete it first to initialize it."
148
- exit
149
- end
150
- p template = File.join(@template_dir,'template_help.org')
151
- FileUtils::Verbose.cp(template,target_help)
152
- end
153
-
154
- def edit_help(file)
155
- target_help = File.join(@local_help_dir,file)
156
- ['.yml','.org'].each do |ext|
157
- p target_help += ext if local_help_entries.member?(file+ext)
158
- end
159
- system "emacs #{target_help}"
160
- end
161
-
162
- def local_help_entries
163
- entries= []
164
- Dir.entries(@local_help_dir).each{|file|
165
- next unless file.include?('_')
166
- next if file[0]=='#' or file[-1]=='~' or file[0]=='.'
167
- next if file.match(/(.+)_e\.org/) # OK?
168
- entries << file
169
- }
170
- return entries
171
- end
172
-
173
- def auto_load(file_path)
174
- case File.extname(file_path)
175
- when '.yml'
176
- cont = YAML.load(File.read(file_path))
177
- when '.org'
178
- cont = OrgToYaml.new(file_path).help_cont
179
- else
180
- puts "Not handling file types of #{file}"
181
- end
182
- cont
183
- end
184
-
185
- def list_helps
186
- print "Specific help file:\n"
187
- local_help_entries.each do |file|
188
- file_path=File.join(@local_help_dir,file)
189
- title = file.split('.')[0]
190
- begin
191
- help = auto_load(file_path)
192
- rescue=> eval
193
- p eval.to_s.red
194
- print "\n YAML load error in #{file}.".red
195
- print " Revise it by "+"my_help --edit #{title}\n".red
196
- exit
197
- end
198
- desc = help[:head][:cont].split("\n")[0]
199
- print " #{title}\t: #{desc}\n".blue
200
- end
201
- end
202
-
203
- end
204
- end
@@ -1,54 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "optparse"
3
- require "yaml"
4
- require 'my_help/org2yml'
5
- require 'my_help/yml2org'
6
- require 'my_help/my_help_controll'
7
- require "fileutils"
8
- require "my_help/version"
9
- require "systemu"
10
- require "colorize"
11
-
12
- module MyHelp
13
- class Command
14
- def self.run(argv=[])
15
- new(argv).execute
16
- end
17
-
18
- def initialize(argv=[])
19
- @argv = argv
20
- @control = MyHelp::Control.new(argv)
21
- end
22
-
23
- def execute
24
- @argv << '--help' if @argv.size==0
25
- command_parser = OptionParser.new do |opt|
26
- opt.on('-v', '--version','show program Version.') { |v|
27
- opt.version = MyHelp::VERSION
28
- puts opt.ver
29
- }
30
- opt.on('-l', '--list [FILE]', 'list all helps or FILE'){|file| @control.list_helps(file)}
31
- opt.on('-i ITEM', '--item NAME', 'show NAME item'){|item| @item = item}
32
- opt.on('-s FILE', '--show FILE', 'show FILE'){|file| @control.show(file, @item)}
33
- opt.on('-e NAME', '--edit NAME', 'edit NAME help(eg test_help)'){|file| @control.edit_help(file) }
34
- opt.on('-m NAME', '--make NAME', 'make NAME help(eq test_help)'){|file| @control.init_help(file)}
35
- opt.on('-y', '--yml2org [FILE]', 'convert FILE from yaml to org format'){|file| yml2org(file)}
36
- opt.on('--delete NAME','delete NAME help'){|file| @control.delete_help(file)}
37
- end
38
- begin
39
- command_parser.parse!(@argv)
40
- rescue=> eval
41
- p eval
42
- end
43
- exit
44
- end
45
-
46
- def yml2org(file)
47
- p target = File.join(@local_help_dir,file+'.yml')
48
- cont = YmlToOrg.new(target).contents
49
- dump = file+'.org'
50
- File.open(dump, 'w'){|file| file.print cont }
51
- delete_help(file)
52
- end
53
- end
54
- end
@@ -1,170 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "optparse"
3
- require "yaml"
4
- require "fileutils"
5
- require "my_help/version"
6
- require "systemu"
7
- require "thor"
8
-
9
- module MyHelp
10
- class Command < Thor
11
- =begin
12
- def self.run(argv=[])
13
- new(argv).execute
14
- end
15
- =end
16
-
17
- def initialize(*args)
18
- super
19
- # @argv = args
20
- @default_help_dir = File.expand_path("../../lib/templates", __FILE__)
21
- @local_help_dir = File.join(ENV['HOME'],'.my_help')
22
- set_help_dir_if_not_exists
23
- end
24
-
25
- desc 'version, -v', 'show program version'
26
- # map "--version" => "version"
27
- map "--version" => "version"
28
- def version
29
- puts MyHelp::VERSION
30
- end
31
-
32
- desc 'delete NAME, --delete NAME','delete NAME help'
33
- map "--delete" => "delete"
34
- def delete_help(file)
35
- del_files=[]
36
- del_files << File.join(@local_help_dir,file)
37
- exe_dir=File.join(File.expand_path('../..',@default_help_dir),'exe')
38
- del_files << File.join(exe_dir,file)
39
- p del_files << File.join(exe_dir,short_name(file))
40
- print "Are you sure to delete these files?[yes]"
41
- if gets.chomp=='yes' then
42
- del_files.each{|file| FileUtils.rm(file,:verbose=>true)}
43
- end
44
- end
45
-
46
- USER_INST_DIR="USER INSTALLATION DIRECTORY:"
47
- INST_DIR="INSTALLATION DIRECTORY:"
48
- desc 'install_local, --install_local','install local after edit helps'
49
- map "--install_local" => "install_local"
50
- def install_local
51
-
52
- Dir.chdir(File.expand_path('../..',@default_help_dir))
53
- p pwd_dir = Dir.pwd
54
- # check that the working dir should not the gem installed dir,
55
- # which destroys itself.
56
- status, stdout, stderr = systemu "gem env|grep '#{USER_INST_DIR}'"
57
- if stdout==""
58
- status, stdout, stderr = systemu "gem env|grep '#{INST_DIR}'"
59
- end
60
- p system_inst_dir = stdout.split(': ')[1].chomp
61
- if pwd_dir == system_inst_dir
62
- puts "Download my_help from github, and using bundle for edit helps\n"
63
- puts "Read README in detail.\n"
64
- exit
65
- end
66
- system "git add -A"
67
- system "git commit -m 'update exe dirs'"
68
- system "Rake install:local"
69
- end
70
-
71
- desc 'clean, --clean', 'clean up exe dir.'
72
- map "--clean" => "clean"
73
- def clean
74
- local_help_entries.each{|file|
75
- next if file.include?('emacs_help') or file.include?('e_h')
76
- next if file.include?('git_help') or file.include?('t_h')
77
- [file, short_name(file)].each{|name|
78
- p target=File.join('exe',name)
79
- FileUtils::Verbose.rm(target)
80
- }
81
- }
82
- end
83
-
84
- desc 'init NAME, --init NAME', 'initialize NAME help(eg test_help).'
85
- map "--init" => "init"
86
- def init(file)
87
- p target_help=File.join(@local_help_dir,file+'.yml')
88
- if File::exists?(target_help)
89
- puts "File exists. rm it first to initialize it."
90
- exit
91
- end
92
- p template = File.join(@default_help_dir,'template_help.yml')
93
- FileUtils::Verbose.cp(template,target_help)
94
- command_template = <<EOS
95
- EOS
96
- end
97
-
98
- desc 'edit NAME, --edit NAME', 'edit NAME help(eg test_help)'
99
- map "--edit" => "edit"
100
- def edit(file)
101
- p target_help=File.join(@local_help_dir,file+'.yml')
102
- system "emacs #{target_help}"
103
- end
104
-
105
-
106
-
107
- desc 'list, --list', 'list specific helps'
108
- map "--list" => "list"
109
- def list
110
- print "Specific help file:\n"
111
- local_help_entries.each{|file|
112
- file_path=File.join(@local_help_dir,file)
113
- help = YAML.load(File.read(file_path))
114
- print " #{file}\t:#{help[:head][0]}\n"
115
- }
116
- end
117
-
118
- desc 'make, --make', 'make executables for all helps.'
119
- map "--make" => "make"
120
- def make
121
- local_help_entries.each{|file|
122
- file_name=file
123
- help_name=file
124
- help_name=File.basename(help_name,".yml")
125
- exe_cont="#!/usr/bin/env ruby\nrequire 'specific_help_opt'\nrequire 'specific_help_thor'\n"
126
- exe_cont << "ENV['HELP_NAME']='#{help_name}'\n"
127
- exe_cont << "help_file = File.join(ENV['HOME'],'.my_help','#{file_name}')\n"
128
- exe_cont << "SpecificHelp::Command.start(ARGV)\n"
129
- exe_cont << "SpecificHelpOpt::Command.run(help_file, ARGV)\n"
130
- [help_name, short_name(help_name)].each{|name|
131
- p target=File.join('exe',name)
132
- File.open(target,'w'){|file| file.print exe_cont}
133
- FileUtils.chmod('a+x', target, :verbose => true)
134
- }
135
- }
136
- install_local
137
- end
138
-
139
- no_commands do
140
- def set_help_dir_if_not_exists
141
- return if File::exists?(@local_help_dir)
142
- FileUtils.mkdir_p(@local_help_dir, :verbose=>true)
143
- Dir.entries(@default_help_dir).each{|file|
144
- next if file=='template_help'
145
- file_path=File.join(@local_help_dir,file)
146
- next if File::exists?(file_path)
147
- FileUtils.cp((File.join(@default_help_dir,file)),@local_help_dir,:verbose=>true)
148
- }
149
- end
150
-
151
- # desc 'test2', 'test3'
152
- def local_help_entries
153
- entries= []
154
- Dir.entries(@local_help_dir).each{|file|
155
- next unless file.include?('_')
156
- next if file[0]=='#' or file[-1]=='~' or file[0]=='.'
157
- entries << file
158
- }
159
- return entries
160
- end
161
-
162
- # desc 'test4', 'test5'
163
- def short_name(file)
164
- file_name=file.split('_')
165
- return file_name[0][0]+"_"+file_name[1][0]
166
- end
167
- end
168
-
169
- end
170
- end