bin/hey: minor refactors & doc revision

This commit is contained in:
Henrik Lissner 2021-02-28 22:30:42 -05:00
parent 6e80c04cd0
commit 80c86bb44f

13
bin/hey
View file

@ -59,11 +59,12 @@ module Hey
def self.sh(args, sudo: false, noerror: false) def self.sh(args, sudo: false, noerror: false)
raise ArgumentError unless args.kind_of?(Array) raise ArgumentError unless args.kind_of?(Array)
args.unshift('sudo') if sudo args.unshift('sudo') if sudo
args.compact!
if @@opts[:dryrun] if @@opts[:dryrun]
print "#{args.compact}\n" print "#{args}\n"
return true return true
else else
result = system "#{args.compact.shelljoin} 2>&1" result = system "#{args.shelljoin} 2>&1"
exit($?.exitstatus) unless noerror or result exit($?.exitstatus) unless noerror or result
return result return result
end end
@ -178,12 +179,12 @@ module Hey
end end
defcmd :swap do defcmd :swap do
desc "Recursively swap nix-store links (or folders thereof) with copies.", desc "Recursively swap nix-store symlinks with copies (or back).",
"The purpose is so you can have copies of your dotfiles that can be modified in", "The purpose is so you can have copies of your dotfiles that can be modified in",
"place (so you can iterate on them quickly instead of 'hey re'ing between", "place (so you can iterate on them quickly instead of 'hey re'ing between",
"changes). Run again to restore the old link(s).\n", "changes). Run again to restore the old link(s).\n",
"Warning: backup your copies, or they will be destroyed when restored!" "Warning: backup your copies, or they will be destroyed when restored!"
args "PATH", "[PATHS...]" args "PATH", "[PATH...]"
lambda do |args| lambda do |args|
for target in args for target in args
if File.directory? target if File.directory? target
@ -347,8 +348,8 @@ module Hey
opt.separator (@@commands.values opt.separator (@@commands.values
.reject { |c| c.desc.empty? } .reject { |c| c.desc.empty? }
.sort { |a,b| a.name <=> b.name } .sort { |a,b| a.name <=> b.name }
.map { |c| " %-18s %s\n" % ["#{c.name} #{@@alias.key(c.name)}", .map { |c| " %-22s %s\n" % ["#{c.name} #{c.args.join ' '}",
c.desc[0]]}) c.desc[0]]})
opt.separator "\nOptions:" opt.separator "\nOptions:"
opt.on '-d', '--dryrun', "Don't change anything; preform dry run" opt.on '-d', '--dryrun', "Don't change anything; preform dry run"
opt.on '-D', '--debug', "Show trace on nix errors" opt.on '-D', '--debug', "Show trace on nix errors"