about summary refs log tree commit homepage
path: root/bin/dtas-sourceedit
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-31 06:28:04 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-31 06:34:05 +0000
commit964bdd3a058670d0e3cf6f26dbd17d85e19c67f3 (patch)
treebf5b508c86ab74150f96d43ef71bf8d0c0a7ed29 /bin/dtas-sourceedit
parent5c90135e4b7b2d1a5bafe2f9a8df45449fc855fe (diff)
downloaddtas-964bdd3a058670d0e3cf6f26dbd17d85e19c67f3.tar.gz
This should make it easy to save/load sink profiles depending on
the users mood.  One could easily create different profiles
depending on different listening criteria.

  dtas-ctl source cat sox > casual.yml
  dtas-sourceedit sox < critical.yml
Diffstat (limited to 'bin/dtas-sourceedit')
-rwxr-xr-xbin/dtas-sourceedit31
1 files changed, 23 insertions, 8 deletions
diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit
index a511793..0c8aeb5 100755
--- a/bin/dtas-sourceedit
+++ b/bin/dtas-sourceedit
@@ -5,22 +5,33 @@ require 'dtas/edit_client'
 include DTAS::EditClient
 c = client_socket
 sources = c.req('source ls') || "(unknown)"
-usage = "Usage: #{DTAS_PROGNAME} SOURCENAME\n" \
+usage = "Usage: #{DTAS_PROGNAME} [-n|--dry-run][-V|--verbose] SOURCENAME\n" \
         "available SOURCENAME values: #{sources}"
+
+# use a real option parser if we have anything more complex
+dry_run = !!(ARGV.delete('-n') || ARGV.delete('--dry-run'))
+verbose = !!(ARGV.delete('-V') || ARGV.delete('--verbose'))
+
 ARGV.size <= 1 or abort usage
 name = ARGV[0] || "sox"
 
-tmp = tmpyaml
+st_in = $stdin.stat
+
 buf = c.req(%W(source cat #{name}))
 abort(buf) if buf =~ /\AERR/
 orig = YAML.load(buf)
 
-tmp.write(buf << DTAS_DISCLAIMER)
-cmd = "#{editor} #{tmp.path}"
-system(cmd) or abort "#{cmd} failed: #$?"
-tmp.rewind
-source = YAML.load(tmp.read)
+if st_in.file? || st_in.pipe?
+  tmp = $stdin
+else
+  tmp = tmpyaml
+  tmp.write(buf << DTAS_DISCLAIMER)
+  cmd = "#{editor} #{tmp.path}"
+  system(cmd) or abort "#{cmd} failed: #$?"
+  tmp.rewind
+end
 
+source = YAML.load(tmp.read)
 cmd = %W(source ed #{name})
 update_cmd_env(cmd, orig, source)
 
@@ -29,4 +40,8 @@ update_cmd_env(cmd, orig, source)
   cmd << "#{field}=#{source[field]}"
 end
 
-c.req_ok(cmd)
+if verbose || dry_run
+  warn Shellwords.join(cmd)
+end
+
+c.req_ok(cmd) unless dry_run