Commit 682b124a authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller
Browse files

CLI usage

parent 4ac7a80d
...@@ -47,7 +47,6 @@ end ...@@ -47,7 +47,6 @@ end
class Grub1Image < GrubImage class Grub1Image < GrubImage
def parse def parse
@lines.each do |line| @lines.each do |line|
puts line
command, args = line.split(nil,2) command, args = line.split(nil,2)
case command case command
when "kernel" when "kernel"
...@@ -118,7 +117,6 @@ class Grub1ConfigFile < GrubConfigFile ...@@ -118,7 +117,6 @@ class Grub1ConfigFile < GrubConfigFile
image_lines = nil image_lines = nil
image_title = nil image_title = nil
@lines.each do |line| @lines.each do |line|
puts line
line.strip! line.strip!
next if line.length == 0 next if line.length == 0
next if line.start_with?("#") next if line.start_with?("#")
...@@ -127,8 +125,9 @@ class Grub1ConfigFile < GrubConfigFile ...@@ -127,8 +125,9 @@ class Grub1ConfigFile < GrubConfigFile
if image_title if image_title
self.add_image(Grub1Image.new(image_title, image_lines)) self.add_image(Grub1Image.new(image_title, image_lines))
end end
image_lines = [] image_lines = []
image_title = line image_title = line.split(nil, 2)[1]
next next
end end
...@@ -176,7 +175,7 @@ class Grub2ConfigFile < GrubConfigFile ...@@ -176,7 +175,7 @@ class Grub2ConfigFile < GrubConfigFile
if m = line.match('^menuentry ["\'](.*)["\'] (.*)\{') then if m = line.match('^menuentry ["\'](.*)["\'] (.*)\{') then
raise "nested menuentry" if image_title != nil raise "nested menuentry" if image_title != nil
image_lines = [] image_lines = []
image_title = line image_title = m[1]
next next
end end
...@@ -213,8 +212,26 @@ class Grub2ConfigFile < GrubConfigFile ...@@ -213,8 +212,26 @@ class Grub2ConfigFile < GrubConfigFile
end end
def usage()
puts "usage: " + File.basename(__FILE__) + " <config file> <1/2>"
end
if __FILE__ == $0 if __FILE__ == $0
cfg = Grub1ConfigFile.new(ARGV[0]) if ARGV.length != 2
usage()
raise "Not enough arguments"
end
type = ARGV[1].to_i
if type == 1 then
cfg = Grub1ConfigFile.new(ARGV[0])
elsif type == 2 then
cfg = Grub2ConfigFile.new(ARGV[0])
else
usage()
raise "Type should be either 1 or 2"
end
cfg.parse cfg.parse
cfg.print cfg.print
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment