about summary refs log tree commit homepage
path: root/bin/dtas-sinkedit
blob: 3cf3a56dbea4f49817896d29336ead522320c9a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require 'dtas/edit_client'
include DTAS::EditClient
c = client_socket
sinks = c.req('sink ls') || "(unknown)"
usage = "Usage: #{DTAS_PROGNAME} SINKNAME\n" \
        "available SINKNAME values: #{sinks}"
ARGV.size == 1 or abort usage
name = ARGV[0]

tmp = tmpyaml
buf = c.req(%W(sink 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: #$?"
sink = YAML.load(File.read(tmp.path))

cmd = %W(sink ed #{name})
update_cmd_env(cmd, orig, sink)

# both of these default to false
%w(nonblock active).each do |field|
  cmd << "#{field}=#{sink[field] ? 'true' : 'false'}"
end

%w(prio).each do |field|
  value = sink[field] and cmd << "#{field}=#{value}"
end

%w(pipe_size).each { |field| cmd << "#{field}=#{sink[field]}" }

# nil OK
%w(command).each do |field|
  cmd << "#{field}=#{sink[field]}"
end

c.req_ok(cmd)