mdq 0.5.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f15383d8943cba2f10e8204a31fde8117580ad57a94d0141ad898a5ed50b6a
4
- data.tar.gz: ff937fc11de10ff1a1f97176a19cafa0aea59bf3cfeb18dd183ff79b5592868c
3
+ metadata.gz: eb4e645a90b2083463ab42641ac31601a9b433a1ab8c163bac6c50ad8f23ea83
4
+ data.tar.gz: f9ee18ecb1ba26fc5c22be56cbef9488a56c10881b911d3895eb0a37191e7f96
5
5
  SHA512:
6
- metadata.gz: 10a89282279e49ebf393d06d9af0e2d1483a958901f3f40b0a321e2c59f0ff16e9388f1d186f7af2c75556d33994e14f9228b258c7453dd819c7fbb36c509006
7
- data.tar.gz: '09a80da76956894938b457d9c4ff1ab5d24093d84f5069e7e43ff79ecf3952c3d57888f16eaf75845cd3b51b6e1cdaf17dc8fc731d99f36fa2fb979333535c4f'
6
+ metadata.gz: 1cb781ce60a3916842174e8da0f76dc63deb92d4a4f3f2e58e1bafe76f34c2d1947a6ae169690a380d4541b33733f0adb2377eeac257124ead43839b4dfa6bb6
7
+ data.tar.gz: 574b835238868b31e97871e259d3f3d8e9155b1dcf2b6d1e0561f329dc057e6e80054a69d0f3e327cdf0f68e44a7c6fced9e175c9ebcdab652367801df98d124
data/README.base.md CHANGED
@@ -22,12 +22,12 @@ Check the software installation status.
22
22
  $ mdq check
23
23
  ```
24
24
 
25
- ## List
25
+ ## Devices
26
26
 
27
- It's easy to use.
27
+ Show mobile devices.
28
28
 
29
29
  ```
30
- $ mdq list
30
+ $ mdq devices
31
31
  [
32
32
  {
33
33
  "id": 1,
@@ -80,6 +80,17 @@ $ mdq list
80
80
  ]
81
81
  ```
82
82
 
83
+ ## Apss
84
+
85
+ Show apps.
86
+
87
+ ```
88
+ $ mdq apps
89
+ ```
90
+
91
+
92
+ ## List
93
+
83
94
  You can filter using SQL.
84
95
 
85
96
  ```
@@ -122,20 +133,20 @@ $ mdq list -q='select * from apps'
122
133
  Take a screenshot on Android.
123
134
 
124
135
  ```
125
- $ mdq list --cap='/Users/xxxxx/'
136
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
126
137
  ```
127
138
 
128
139
  Install the app.
129
140
 
130
141
  ```
131
- $ mdq list --install='/Users/xxxxx/example.apk'
132
- $ mdq list --install='/Users/xxxxx/example.ipa'
142
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
143
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
133
144
  ```
134
145
 
135
146
  Uninstall the app.
136
147
 
137
148
  ```
138
- $ mdq list --uninstall='com.example.app'
149
+ $ mdq uninstall -i='com.example.app' -u='UDID'
139
150
  ```
140
151
 
141
152
 
data/README.ja.md CHANGED
@@ -17,12 +17,12 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
- ## List
20
+ ## Devices
21
21
 
22
- It's easy to use.
22
+ Show mobile devices.
23
23
 
24
24
  ```
25
- $ mdq list
25
+ $ mdq devices
26
26
  [
27
27
  {
28
28
  "id": 1,
@@ -75,6 +75,17 @@ $ mdq list
75
75
  ]
76
76
  ```
77
77
 
78
+ ## Apss
79
+
80
+ Show apps.
81
+
82
+ ```
83
+ $ mdq apps
84
+ ```
85
+
86
+
87
+ ## List
88
+
78
89
  You can filter using SQL.
79
90
 
80
91
  ```
@@ -117,20 +128,20 @@ $ mdq list -q='select * from apps'
117
128
  Take a screenshot on Android.
118
129
 
119
130
  ```
120
- $ mdq list --cap='/Users/xxxxx/'
131
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
121
132
  ```
122
133
 
123
134
  Install the app.
124
135
 
125
136
  ```
126
- $ mdq list --install='/Users/xxxxx/example.apk'
127
- $ mdq list --install='/Users/xxxxx/example.ipa'
137
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
138
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
128
139
  ```
129
140
 
130
141
  Uninstall the app.
131
142
 
132
143
  ```
133
- $ mdq list --uninstall='com.example.app'
144
+ $ mdq uninstall -i='com.example.app' -u='UDID'
134
145
  ```
135
146
 
136
147
 
data/README.md CHANGED
@@ -17,12 +17,12 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
- ## List
20
+ ## Devices
21
21
 
22
- It's easy to use.
22
+ Show mobile devices.
23
23
 
24
24
  ```
25
- $ mdq list
25
+ $ mdq devices
26
26
  [
27
27
  {
28
28
  "id": 1,
@@ -75,6 +75,17 @@ $ mdq list
75
75
  ]
76
76
  ```
77
77
 
78
+ ## Apss
79
+
80
+ Show apps.
81
+
82
+ ```
83
+ $ mdq apps
84
+ ```
85
+
86
+
87
+ ## List
88
+
78
89
  You can filter using SQL.
79
90
 
80
91
  ```
@@ -117,20 +128,20 @@ $ mdq list -q='select * from apps'
117
128
  Take a screenshot on Android.
118
129
 
119
130
  ```
120
- $ mdq list --cap='/Users/xxxxx/'
131
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
121
132
  ```
122
133
 
123
134
  Install the app.
124
135
 
125
136
  ```
126
- $ mdq list --install='/Users/xxxxx/example.apk'
127
- $ mdq list --install='/Users/xxxxx/example.ipa'
137
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
138
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
128
139
  ```
129
140
 
130
141
  Uninstall the app.
131
142
 
132
143
  ```
133
- $ mdq list --uninstall='com.example.app'
144
+ $ mdq uninstall -i='com.example.app' -u='UDID'
134
145
  ```
135
146
 
136
147
 
data/lib/mdq/cli.rb CHANGED
@@ -19,17 +19,69 @@ module Mdq
19
19
 
20
20
  desc 'check', 'Check the software installation status'
21
21
  def check
22
- Mdq::Check.new
22
+ db = Mdq::DB.new
23
+ puts "adb is installed: #{db.android_discoverable?}"
24
+ puts "Xcode is installed: #{db.apple_discoverable?}"
23
25
  end
24
26
 
25
- desc 'list', 'Show mobile devices'
26
- method_option :output, desc: 'Save the results as a JSON file', aliases: '-o'
27
- method_option :query, desc: 'SQL to filter devices', aliases: '-q'
28
- method_option :cap, desc: 'Path to save screenshots(Android only)'
29
- method_option :install, desc: 'Installing the app(apk, ipa)'
30
- method_option :uninstall, desc: 'Uninstalling the app(Package Name, Bundle Identifier)'
27
+ desc 'devices', 'Show mobile devices'
28
+ method_option :android, desc: 'Show Android devices', default: true,
29
+ type: :boolean
30
+ method_option :apple, desc: 'Show Apple devices', default: true,
31
+ type: :boolean
32
+ def devices
33
+ db = Mdq::DB.new
34
+ db.get(is_android: options[:android], is_apple: options[:apple], is_apps: false)
35
+ puts(JSON.pretty_generate(Device.all.as_json))
36
+ end
37
+
38
+ desc 'apps', 'Show mobile apps'
39
+ method_option :android, desc: 'Show Android devices', default: true,
40
+ type: :boolean
41
+ method_option :apple, desc: 'Show Apple devices', default: true,
42
+ type: :boolean
43
+ def apps
44
+ db = Mdq::DB.new
45
+ db.get(is_android: options[:android], is_apple: options[:apple])
46
+ puts(JSON.pretty_generate(App.all.as_json))
47
+ end
48
+
49
+ desc 'list', 'Show mobile devices or apps'
50
+ method_option :query, desc: 'SQL to filter devices or apps', aliases: '-q', required: true
31
51
  def list
32
- Mdq::List.new(options)
52
+ db = Mdq::DB.new
53
+ db.get
54
+ result = db.query(options['query'])
55
+ puts(JSON.pretty_generate(result.as_json))
56
+ end
57
+
58
+ desc 'cap', 'Path to save screenshots(Android only)'
59
+ method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
60
+ method_option :output, desc: 'Save to file', aliases: '-o', required: true
61
+ def cap
62
+ db = Mdq::DB.new
63
+ db.get(is_apps: false)
64
+ db.device_screencap(options[:output], options[:udid])
65
+ end
66
+
67
+ desc 'install', 'Installing the app(apk, apex, ipa)'
68
+ method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
69
+ method_option :input, desc: 'Path to the app file', aliases: '-i', required: true
70
+ method_option :replace, desc: 'Replace the app if it is already installed', aliases: '-r', default: false,
71
+ type: :boolean
72
+ def install
73
+ db = Mdq::DB.new
74
+ db.get(is_apps: false)
75
+ db.app_install(options[:input], options[:udid], options[:replace])
76
+ end
77
+
78
+ desc 'uninstall', 'Uninstalling the app'
79
+ method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
80
+ method_option :input, desc: 'Path to the app', aliases: '-i', required: true
81
+ def uninstall
82
+ db = Mdq::DB.new
83
+ db.get(is_apps: false)
84
+ db.app_uninstall(options[:input], options[:udid])
33
85
  end
34
86
  end
35
87
  end
data/lib/mdq/db.rb CHANGED
@@ -8,63 +8,86 @@ require 'fileutils'
8
8
  module Mdq
9
9
  # DB
10
10
  class DB < Discovery
11
- # クエリの実行
12
- def get(sql)
11
+ # デバイスとアプリの取得
12
+ def get(is_android: true, is_apple: true, is_apps: true)
13
13
  reset
14
14
  # デバイスの発見
15
- android_discover
16
- apple_discover
15
+ android_discover if is_android
16
+ apple_discover if is_apple
17
17
 
18
- if sql
19
- Device.all.each do |model|
20
- # インストール済みAppの取得
21
- if model.android?
22
- android_apps(model.udid)
23
- else
24
- apple_apps(model.udid)
25
- end
26
- end
18
+ return unless is_apps
27
19
 
28
- begin
29
- ActiveRecord::Base.connection.execute(sql)
30
- rescue StandardError => e
31
- { result: e }
20
+ Device.all.each do |model|
21
+ # インストール済みAppの取得
22
+ if model.android?
23
+ android_apps(model.udid)
24
+ else
25
+ apple_apps(model.udid)
32
26
  end
33
- else
34
- Device.all
35
27
  end
36
28
  end
37
29
 
30
+ # クエリの実行
31
+ def query(sql)
32
+ ActiveRecord::Base.connection.execute(sql)
33
+ rescue StandardError
34
+ []
35
+ end
36
+
38
37
  # Androidデバイスのスクリーンショットを撮る
39
- def device_screencap(output, udid, is_android)
40
- return unless is_android
38
+ def device_screencap(output, udid)
39
+ device = Device.find_by(udid: udid)
40
+ if device.nil? || !device.android?
41
+ warn 'Device not found or not an Android device.'
42
+ return
43
+ end
41
44
 
42
45
  FileUtils.mkdir_p(output)
43
- file = "/sdcard/#{udid}.png"
44
- adb_command("shell screencap -p #{file}", udid)
45
- adb_command("pull #{file} #{output}", udid)
46
- adb_command("adb shell rm #{file}")
47
-
48
- { command: 'cap', udid: udid, result: nil }
46
+ file = "#{udid}-#{Time.now.strftime('%y%m%d-%H%M%S')}.png"
47
+ full_path = "/sdcard/#{file}"
48
+ adb_command("shell screencap -p #{full_path}", udid)
49
+ adb_command("pull #{full_path} #{output}", udid)
50
+ adb_command("shell rm #{full_path}", udid)
49
51
  end
50
52
 
51
53
  # Appをインストールする
52
- def app_install(input, udid, is_android)
53
- output, = adb_command("install #{input}", udid) if is_android && input.end_with?('.apk')
54
- output, = apple_command("device install app #{input}", udid) if !is_android && input.end_with?('.ipa')
54
+ def app_install(input, udid, is_replace)
55
+ device = Device.find_by(udid: udid)
56
+ if device.nil?
57
+ warn 'Device not found.'
58
+ return
59
+ end
55
60
 
56
- { command: 'install', udid: udid, result: output }
61
+ if device.android?
62
+ if is_replace
63
+ output, error = adb_command("install -r #{input}", udid)
64
+ else
65
+ output, error = adb_command("install #{input}", udid)
66
+ end
67
+ else
68
+ output, error = apple_command("device install app #{input}", udid)
69
+ end
70
+
71
+ puts output unless output.empty?
72
+ warn error unless error.empty?
57
73
  end
58
74
 
59
75
  # Appをアンインストールする
60
- def app_uninstall(input, udid, is_android)
61
- if is_android
62
- output, = adb_command("uninstall #{input}", udid)
76
+ def app_uninstall(input, udid)
77
+ device = Device.find_by(udid: udid)
78
+ if device.nil?
79
+ warn 'Device not found.'
80
+ return
81
+ end
82
+
83
+ if device.android?
84
+ output, error = adb_command("uninstall #{input}", udid)
63
85
  else
64
- output, = apple_command("device uninstall app #{input}", udid)
86
+ output, error = apple_command("device uninstall app #{input}", udid)
65
87
  end
66
88
 
67
- { command: 'uninstall', udid: udid, result: output }
89
+ puts output unless output.empty?
90
+ warn error unless error.empty?
68
91
  end
69
92
  end
70
93
  end
data/lib/mdq/discovery.rb CHANGED
@@ -135,7 +135,7 @@ module Mdq
135
135
  total_disk: total_disk,
136
136
  available_disk: available_disk,
137
137
  used_disk: used_disk,
138
- capacity: (used_disk / total_disk) * 100,
138
+ capacity: (used_disk.to_f / total_disk) * 100,
139
139
  human_readable_total_disk: number_to_human_size(total_disk, k),
140
140
  human_readable_available_disk: number_to_human_size(available_disk, k),
141
141
  human_readable_used_disk: number_to_human_size(used_disk, k),
data/lib/mdq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mdq
4
- VERSION = '0.5.2'
4
+ VERSION = '1.0.1'
5
5
  end
data/lib/mdq.rb CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  require_relative 'mdq/version'
4
4
  require 'mdq/cli'
5
- require 'mdq/check'
6
- require 'mdq/list'
7
- require 'mdq/output_builder'
8
5
  require 'mdq/discovery'
9
6
  require 'mdq/db'
10
7
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - arthur87
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-06-07 00:00:00.000000000 Z
10
+ date: 2026-04-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rubocop
@@ -85,12 +84,9 @@ files:
85
84
  - Rakefile
86
85
  - exe/mdq
87
86
  - lib/mdq.rb
88
- - lib/mdq/check.rb
89
87
  - lib/mdq/cli.rb
90
88
  - lib/mdq/db.rb
91
89
  - lib/mdq/discovery.rb
92
- - lib/mdq/list.rb
93
- - lib/mdq/output_builder.rb
94
90
  - lib/mdq/version.rb
95
91
  homepage: https://github.com/arthur87/mdq
96
92
  licenses:
@@ -98,7 +94,6 @@ licenses:
98
94
  metadata:
99
95
  homepage_uri: https://github.com/arthur87/mdq
100
96
  source_code_uri: https://github.com/arthur87/mdq
101
- post_install_message:
102
97
  rdoc_options: []
103
98
  require_paths:
104
99
  - lib
@@ -113,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
108
  - !ruby/object:Gem::Version
114
109
  version: '0'
115
110
  requirements: []
116
- rubygems_version: 3.3.3
117
- signing_key:
111
+ rubygems_version: 3.6.3
118
112
  specification_version: 4
119
113
  summary: mdq is a command line tool for displaying information about Android and Apple
120
114
  devices.
data/lib/mdq/check.rb DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mdq'
4
-
5
- # Mdq
6
- module Mdq
7
- # Check
8
- class Check
9
- def initialize
10
- ob = Mdq::OutputBuilder.new
11
-
12
- db = Mdq::DB.new
13
- ob.add(show_message('adb', db.android_discoverable?))
14
- ob.add(show_message('Xcode', db.apple_discoverable?))
15
-
16
- ob.print
17
- end
18
-
19
- private
20
-
21
- def show_message(name, discoverable)
22
- if discoverable
23
- { result: "#{name} is installed." }
24
- else
25
- { result: "#{name} is not installed." }
26
- end
27
- end
28
- end
29
- end
data/lib/mdq/list.rb DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mdq'
4
-
5
- # Mdq
6
- module Mdq
7
- # List
8
- class List
9
- def initialize(options)
10
- db = Mdq::DB.new
11
-
12
- query = options['query']
13
- models = db.get(query)
14
-
15
- output = JSON.pretty_generate(models.as_json)
16
- puts output
17
- if options['output']
18
- File.open(options['output'], 'w') do |f|
19
- f.write(output)
20
- end
21
- end
22
-
23
- ob = Mdq::OutputBuilder.new
24
-
25
- models.each do |device|
26
- model = Device.find_by(udid: device.udid)
27
- udid = model.udid
28
- is_android = model.android?
29
-
30
- ob.add(db.device_screencap(options[:cap], udid, is_android)) if options[:cap]
31
- ob.add(db.app_install(options[:install], udid, is_android)) if options[:install]
32
- ob.add(db.app_uninstall(options[:uninstall], udid, is_android)) if options[:uninstall]
33
- rescue StandardError
34
- # none
35
- end
36
-
37
- ob.print
38
- end
39
- end
40
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mdq'
4
-
5
- # Mdq
6
- module Mdq
7
- # OutputBuilder
8
- class OutputBuilder
9
- def initialize
10
- @result = []
11
- end
12
-
13
- def clear
14
- @result = []
15
- end
16
-
17
- def add(new_result)
18
- @result << new_result
19
- end
20
-
21
- def print
22
- return if @result == []
23
-
24
- puts JSON.pretty_generate(@result.as_json)
25
- end
26
- end
27
- end