Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updates to error handling and messages

  • Loading branch information...
commit 5496bf57c8f80e23001365d8213a5f5810aa9aaa 1 parent 668982f
@lemieuxster authored
Showing with 30 additions and 11 deletions.
  1. +30 −11 please.rb
View
41 please.rb
@@ -5,7 +5,7 @@
yamlfile = yamldir + "/please.yml"
if ARGV.length == 0
- puts "please specify an alias or add a new one"
+ puts "Please specify an alias or add a new one. --help for help."
Process.exit
end
@@ -35,9 +35,15 @@
end
if (arguments[0] === '--help')
- puts "--add 'new alias' 'aliased command' 'working dir'(optional)\n"
- puts "--del 'new alias'"
- puts "--list to see list of aliases\n"
+ puts "\n"
+ puts "Please - an alias manager by David LeMieux\n\n"
+ puts "Commands:\n"
+ puts " --add 'new alias' 'aliased command' 'working dir'(optional)\n"
+ puts " --del 'new alias'"
+ puts " --list to see list of aliases\n"
+ puts "\n"
+ puts "You can store your please aliases in a custom directory by exporting PLEASEDIR\n"
+ puts "\n"
Process.exit
elsif (arguments[0] === '--list')
aliasmap = aliasmap.sort {|a,b| a[0]<=>b[0]}
@@ -47,7 +53,7 @@
Process.exit
elsif (arguments[0] === '--add')
if (!arguments[1] || !arguments[2])
- puts "not enough arguments"
+ puts "Not enough arguments."
Process.exit
end
@@ -56,13 +62,13 @@
aliasmap[arguments[1]] = newcommand
File.open(yamlfile, "w") {|f| f.write((aliasmap.to_yaml()))}
rescue
- puts "error adding alias to file"
+ puts "Error adding alias to file."
end
Process.exit
elsif (arguments[0] === '--del')
if (!arguments[1])
- puts "not enough arguments"
+ puts "Not enough arguments."
Process.exit
end
@@ -70,7 +76,7 @@
aliasmap.delete(arguments[1])
File.open(yamlfile, "w") {|f| f.write((aliasmap.to_yaml()))}
rescue
- puts "error deleting alias from file"
+ puts "Error deleting alias from file."
end
Process.exit
@@ -78,20 +84,33 @@
begin
aliname = ""
+
arguments.each_with_index do|arg, index|
aliname << arg
if (index < arguments.length - 1)
aliname << " "
end
end
- #puts aliname
+
+# puts aliname
ali = aliasmap[aliname]
+
+ if (ali == nil)
+ puts "No alias found."
+ Process.exit
+ end
+
if (ali["dir"] && ali["dir"] != "")
Dir.chdir(ali["dir"])
end
+
alicmd = ali["command"]
+# puts alicmd
+
+ #TODO loop over "tokens" in alicmd and ask for inputs
+
exec( alicmd )
+
rescue StandardError => error
- puts "could not execute alias"
- puts error
+ puts "Error executing alias."
end
Please sign in to comment.
Something went wrong with that request. Please try again.