46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/dita-topic/cli.rb', line 46
def parse_args argv
parser = OptionParser.new do |opt|
opt.banner = "Usage: #{@name} [OPTION...] [FILE...]\n"
opt.banner += " #{@name} -h|-v\n\n"
opt.on('-o', '--out-file FILE', 'specify the output file; by default, the output file name is based on the input file') do |output|
@opts[:output] = (output.strip == '-') ? $stdout : output
end
opt.on('-a', '--attribute ATTRIBUTE', 'set a document attribute in the form of name, name!, or name=value pair; can be supplied multiple times') do |value|
@attr.append value
end
opt.on('-s', '--no-header-footer', 'disable enclosing the content in <topic> and generating <title>') do
@opts[:standalone] = false
end
opt.separator ''
opt.on('-p', '--prepend-file FILE', 'prepend a file to all input files; can be supplied multiple times') do |file|
raise OptionParser::InvalidArgument, "not a file: #{file}" unless File.exist? file and File.file? file
raise OptionParser::InvalidArgument, "file not readable: #{file}" unless File.readable? file
@prep.append file
end
opt.on('-I', '--no-includes', 'disable processing of include directives; specify this option twice to also apply on prepended files') do
@opts[:no_includes] += 1
end
opt.on('-A', '--no-modules', 'disable processing of include directives with assemblies and modules') do
@opts[:modules] = false
end
opt.separator ''
opt.on('-l', '--author-line', 'enable processing of author lines as metadata') do
@attr.append 'dita-topic-authors=on'
end
opt.on('-t', '--section-type', 'add content type as outputclass to sections') do
@attr.append 'dita-topic-type=on'
end
opt.on('-C', '--no-callouts', 'disable processing of callouts') do
@attr.append 'dita-topic-callouts=off'
end
opt.on('-M', '--no-semantic-markup', 'disable processing of semantic markup') do
@attr.append 'dita-topic-semantic=off'
end
opt.on('-S', '--no-sidebars', 'disable processing of sidebars') do
@attr.append 'dita-topic-sidebars=off'
end
opt.on('-T', '--no-titles', 'disable processing of floating titles') do
@attr.append 'dita-topic-titles=off'
end
opt.separator ''
opt.on('-h', '--help', 'display this help and exit') do
puts opt
exit
end
opt.on('-v', '--version', 'display version information and exit') do
puts "#{@name} #{VERSION}"
exit
end
end
args = parser.parse argv
if args.length == 0 or args[0].strip == '-'
return [$stdin]
end
args.each do |file|
raise OptionParser::InvalidArgument, "not a file: #{file}" unless File.exist? file and File.file? file
raise OptionParser::InvalidArgument, "file not readable: #{file}" unless File.readable? file
end
return args
end
|