alsa_aconnect 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 275d59e874cb491657df6c74926c4ebc806b21d3d8ae827a48cea410e6cd2c3f
4
- data.tar.gz: cb9cb058ce0e86e6359eb6c4b8f9411ff8c904ee68ace706fd523538bf6bfb37
3
+ metadata.gz: 15f9788a8fe37cd553690282394fdac0bd2bf30de7dccffd6b83540013ba55f4
4
+ data.tar.gz: 01d4786195dccd53b11184be34d34eae6da37a2d0bab6e79ec0fc2125926d7b6
5
5
  SHA512:
6
- metadata.gz: 81e6394325a1d7ac7867942b0f03a118cb987e4d7c1a836ad74cebdf4363305f1ab5acc1af46a4fad259c030e9f20bc9be33c22c978c4001ff18e8e0624f808e
7
- data.tar.gz: c629519f0baba38ba006b571474b98d624208b9e37d760d39bd7b6fd835107a7b69ea7c64b3395c5780bce2b4b5bf26f364bfe0fdd581848f82bd11a10a05999
6
+ metadata.gz: 9ceb96edc8acb00da4bc75e8ce8c972cdd5486b39d6587b1513da9abc57edc3abd9625e25fa6d8297d63952053a61e68632b22cb412ae77c5ac992dcd6a5173e
7
+ data.tar.gz: 6309907438e7bdc992be734b2ef81c60ca2e510a2721bef9b0b14f796f6d58c5e0c035fa6b335a5a77b9f3974141de669d4f3f70c131ec02c92e15ae2d14d27d
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.2 (2020-05-16)
6
+ * simplify command run
7
+
5
8
  ## 0.1.1 (2020-05-16)
6
9
  * fix #connect and #disconnect
7
10
 
data/README.md CHANGED
@@ -24,16 +24,21 @@ Or install it yourself as:
24
24
  require 'alsa/aconnect'
25
25
 
26
26
  def print_client(client)
27
- puts "#{client.id} => #{client.name} [type=#{client.type},card=#{client.card},pid=#{client.pid}]"
27
+ tags = {
28
+ type: client.type,
29
+ card: client.card,
30
+ pid: client.pid
31
+ }.compact.map { |k, v| "#{k}=#{v}" }.join(',')
32
+ lines = ["#{client.id} => #{client.name} [#{tags}]"]
28
33
  client.ports.each do |port|
29
34
  if port.connected_to_type
30
35
  connected = "connected to #{port.connected_to_type} #{port.connected_to_client_id}:#{port.connected_to_port_id}"
31
36
  else
32
37
  connected = 'not connected'
33
38
  end
34
- puts " #{port.id} => #{port.name} (#{connected})"
39
+ lines.push " #{port.id} => #{port.name} (#{connected})"
35
40
  end
36
- puts ''
41
+ puts(*lines, '')
37
42
  end
38
43
 
39
44
  input_clients = ALSA::Aconnect.input_clients
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'alsa/command'
4
3
  require 'alsa/aconnect/version'
5
4
  require 'alsa/aconnect/error'
6
5
  require 'alsa/aconnect/cmd'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
4
+
3
5
  module ALSA
4
6
  module Aconnect
5
7
  class Cmd
@@ -15,10 +17,12 @@ module ALSA
15
17
  end
16
18
 
17
19
  def run
18
- status, out, err = Command.run(@exec, *@arguments)
19
- raise Error.new(status.exitstatus, err.join("\n")) if status != 0 || !err.empty?
20
+ cmd = [@exec, *@arguments].compact.join(' ')
21
+ out, err, status = Open3.capture3(cmd)
22
+ code = status.exitstatus
23
+ raise Error.new code, err.join("\n") unless code.zero?
20
24
 
21
- out.join("\n")
25
+ out
22
26
  end
23
27
  end
24
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ALSA
4
4
  module Aconnect
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alsa_aconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
@@ -37,7 +37,6 @@ files:
37
37
  - lib/alsa/aconnect/parser.rb
38
38
  - lib/alsa/aconnect/port.rb
39
39
  - lib/alsa/aconnect/version.rb
40
- - lib/alsa/command.rb
41
40
  - lib/alsa_aconnect.rb
42
41
  - man.txt
43
42
  homepage: https://github.com/senid231/alsa_aconnect
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module ALSA
6
- # Util class for shell commands execution
7
- class Command
8
- def self.run(command, *arguments, **options)
9
- new(command, arguments, options).run
10
- end
11
-
12
- attr_reader :command, :arguments, :env, :out, :err
13
-
14
- def initialize(command, arguments, env: {}, out: nil, err: nil)
15
- @command = command
16
- @arguments = arguments
17
- @env = env
18
- @out = out
19
- @err = err
20
- @out_buff = []
21
- @err_buff = []
22
- end
23
-
24
- def run
25
- env_line = env.map { |k, v| "#{k}=#{v}" }.join(' ')
26
- command_line = ([env_line, command] + arguments).reject(&:empty?).join(' ')
27
-
28
- code = raw_execute(command_line)
29
- [code, @out_buff, @err_buff]
30
- end
31
-
32
- private
33
-
34
- def raw_execute(command_line)
35
- Open3.popen3(command_line) do |_stdin, stdout, stderr, wait_thread|
36
- Thread.new do
37
- begin
38
- until (raw_line = stdout.gets).nil?
39
- @out_buff.push(raw_line)
40
- out&.call(raw_line)
41
- end
42
- rescue IOError => _e
43
- # command process was closed and it's ok
44
- end
45
- end
46
- Thread.new do
47
- begin
48
- until (raw_line = stderr.gets).nil?
49
- @err_buff.push(raw_line)
50
- err&.call(raw_line)
51
- end
52
- rescue IOError => _e
53
- # command process was closed and it's ok
54
- end
55
- end
56
- wait_thread.value
57
- end
58
- end
59
- end
60
- end