mdq 1.3.1 → 1.5.0

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: 0c2666a8e5e31b2291afd0f587e36248c1180bf03fe1aa727c3a41ab27cb3a4c
4
- data.tar.gz: fc60f852a4a72bbd99d1a755f17cd9cbef82dd757d4ad3cfadb8b69fe57a76b1
3
+ metadata.gz: 8ba84c3f7c666c4f32a57802aec86dc14dd3c213cc056bdb86b2ee2fa1bc7a1a
4
+ data.tar.gz: 16dffbcf4e63038c4976c95fe0763939b0c6c4736f24802a594f17a30f7e91b9
5
5
  SHA512:
6
- metadata.gz: 5da43c0af4704135bc5fa9b6d94b71f31555c3921b8df271acec69eac15af1d53a41e48655e8a4b88370c13258a9a625729d81db957f7f0dba82753394b0171b
7
- data.tar.gz: e7f994e262a4ca24ad6b334d44b06c3b93b759d47d31f2ebeb7abfdbbf4ba4b41fa88c961239ce198939c8480dc07a3da14db6241880d13fdf52fe65488251ab
6
+ metadata.gz: 5339784eaa9049ce0322ca19199c83d5ef6fd010db98f7ce67f40307861c92b33b9fd715494c440824c396406eff44190d169f955972dff1c920a079422eb4a3
7
+ data.tar.gz: cf3ff9fcc28b265b0f4616e9dae9f0afd714f3b05045c73ee6c8752f49791a3e11dead60f759a1befe048bd6f912271324f1a3fb93ae19bf0cffd8c61c9301db
data/.rubocop.yml CHANGED
@@ -1 +1,4 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: disable
data/README.base.md CHANGED
@@ -22,6 +22,21 @@ Check the software installation status.
22
22
  $ mdq check
23
23
  ```
24
24
 
25
+ The following versions have been tested and confirmed to work.
26
+
27
+ ```
28
+ $ adb --version
29
+ Android Debug Bridge version 1.0.41
30
+ Version 35.0.1-11580240
31
+ Installed as /opt/homebrew/bin/adb
32
+ Running on Darwin 25.5.0 (arm64)
33
+ ```
34
+
35
+ ```
36
+ $ xcrun --version
37
+ xcrun version 72.
38
+ ```
39
+
25
40
  ## Devices
26
41
 
27
42
  Show mobile devices.
@@ -38,6 +53,7 @@ $ mdq devices
38
53
  "platform": "Android",
39
54
  "marketing_name": null,
40
55
  "model": "Pixel 7",
56
+ "physical", true,
41
57
  "build_version": "16",
42
58
  "build_id": "BP31.250502.008",
43
59
  "battery_level": 88,
@@ -62,6 +78,7 @@ $ mdq devices
62
78
  "platform": "iOS",
63
79
  "marketing_name": "iPhone 16 Pro",
64
80
  "model": "iPhone17,1",
81
+ "physical", true,
65
82
  "build_version": "18.4.1",
66
83
  "build_id": "22E252",
67
84
  "battery_level": null,
@@ -105,6 +122,7 @@ $ mdq list -q="select * from devices where platform='iOS'"
105
122
  "platform": "iOS",
106
123
  "marketing_name": "iPhone 16 Pro",
107
124
  "model": "iPhone17,1",
125
+ "physical", true,
108
126
  "build_version": "18.4.1",
109
127
  "build_id": "22E252",
110
128
  "battery_level": null,
@@ -132,7 +150,8 @@ $ mdq list -q='select * from apps'
132
150
 
133
151
  ## Screenshot of a physical device
134
152
 
135
- Take a screenshot on Android.
153
+ Take a screenshot of the physical device.
154
+ For Apple devices, the physical column should be true.
136
155
 
137
156
  ```
138
157
  $ mdq cap -o='/Users/xxxxx/' -u='UDID'
@@ -190,6 +209,7 @@ Details of the devices table.
190
209
  | platform | Always "Android" | hardwareProperties.platform |
191
210
  | marketing_name | Always "null" | hardwareProperties.marketingName |
192
211
  | model | ro.product.model | hardwareProperties.productType |
212
+ | physical | Always true | hardwareProperties.reality |
193
213
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
194
214
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
195
215
  | battery_level | battery | Always "null" |
data/README.ja.md CHANGED
@@ -17,6 +17,21 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
+ The following versions have been tested and confirmed to work.
21
+
22
+ ```
23
+ $ adb --version
24
+ Android Debug Bridge version 1.0.41
25
+ Version 35.0.1-11580240
26
+ Installed as /opt/homebrew/bin/adb
27
+ Running on Darwin 25.5.0 (arm64)
28
+ ```
29
+
30
+ ```
31
+ $ xcrun --version
32
+ xcrun version 72.
33
+ ```
34
+
20
35
  ## Devices
21
36
 
22
37
  Show mobile devices.
@@ -33,6 +48,7 @@ $ mdq devices
33
48
  "platform": "Android",
34
49
  "marketing_name": null,
35
50
  "model": "Pixel 7",
51
+ "physical", true,
36
52
  "build_version": "16",
37
53
  "build_id": "BP31.250502.008",
38
54
  "battery_level": 88,
@@ -57,6 +73,7 @@ $ mdq devices
57
73
  "platform": "iOS",
58
74
  "marketing_name": "iPhone 16 Pro",
59
75
  "model": "iPhone17,1",
76
+ "physical", true,
60
77
  "build_version": "18.4.1",
61
78
  "build_id": "22E252",
62
79
  "battery_level": null,
@@ -100,6 +117,7 @@ $ mdq list -q="select * from devices where platform='iOS'"
100
117
  "platform": "iOS",
101
118
  "marketing_name": "iPhone 16 Pro",
102
119
  "model": "iPhone17,1",
120
+ "physical", true,
103
121
  "build_version": "18.4.1",
104
122
  "build_id": "22E252",
105
123
  "battery_level": null,
@@ -127,7 +145,8 @@ $ mdq list -q='select * from apps'
127
145
 
128
146
  ## Screenshot of a physical device
129
147
 
130
- Take a screenshot on Android.
148
+ Take a screenshot of the physical device.
149
+ For Apple devices, the physical column should be true.
131
150
 
132
151
  ```
133
152
  $ mdq cap -o='/Users/xxxxx/' -u='UDID'
@@ -185,6 +204,7 @@ Details of the devices table.
185
204
  | platform | Always "Android" | hardwareProperties.platform |
186
205
  | marketing_name | Always "null" | hardwareProperties.marketingName |
187
206
  | model | ro.product.model | hardwareProperties.productType |
207
+ | physical | Always true | hardwareProperties.reality |
188
208
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
189
209
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
190
210
  | battery_level | battery | Always "null" |
data/README.md CHANGED
@@ -17,6 +17,21 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
+ The following versions have been tested and confirmed to work.
21
+
22
+ ```
23
+ $ adb --version
24
+ Android Debug Bridge version 1.0.41
25
+ Version 35.0.1-11580240
26
+ Installed as /opt/homebrew/bin/adb
27
+ Running on Darwin 25.5.0 (arm64)
28
+ ```
29
+
30
+ ```
31
+ $ xcrun --version
32
+ xcrun version 72.
33
+ ```
34
+
20
35
  ## Devices
21
36
 
22
37
  Show mobile devices.
@@ -33,6 +48,7 @@ $ mdq devices
33
48
  "platform": "Android",
34
49
  "marketing_name": null,
35
50
  "model": "Pixel 7",
51
+ "physical", true,
36
52
  "build_version": "16",
37
53
  "build_id": "BP31.250502.008",
38
54
  "battery_level": 88,
@@ -57,6 +73,7 @@ $ mdq devices
57
73
  "platform": "iOS",
58
74
  "marketing_name": "iPhone 16 Pro",
59
75
  "model": "iPhone17,1",
76
+ "physical", true,
60
77
  "build_version": "18.4.1",
61
78
  "build_id": "22E252",
62
79
  "battery_level": null,
@@ -100,6 +117,7 @@ $ mdq list -q="select * from devices where platform='iOS'"
100
117
  "platform": "iOS",
101
118
  "marketing_name": "iPhone 16 Pro",
102
119
  "model": "iPhone17,1",
120
+ "physical", true,
103
121
  "build_version": "18.4.1",
104
122
  "build_id": "22E252",
105
123
  "battery_level": null,
@@ -127,7 +145,8 @@ $ mdq list -q='select * from apps'
127
145
 
128
146
  ## Screenshot of a physical device
129
147
 
130
- Take a screenshot on Android.
148
+ Take a screenshot of the physical device.
149
+ For Apple devices, the physical column should be true.
131
150
 
132
151
  ```
133
152
  $ mdq cap -o='/Users/xxxxx/' -u='UDID'
@@ -185,6 +204,7 @@ Details of the devices table.
185
204
  | platform | Always "Android" | hardwareProperties.platform |
186
205
  | marketing_name | Always "null" | hardwareProperties.marketingName |
187
206
  | model | ro.product.model | hardwareProperties.productType |
207
+ | physical | Always true | hardwareProperties.reality |
188
208
  | build_version | ro.build.version.release | deviceProperties.osVersionNumber |
189
209
  | build_id | ro.build.id | deviceProperties.osBuildUpdate |
190
210
  | battery_level | battery | Always "null" |
data/lib/mdq/cli.rb CHANGED
@@ -12,19 +12,19 @@ module Mdq
12
12
  end
13
13
  end
14
14
 
15
- desc 'version', 'Show Version'
15
+ desc 'version', 'Show Version.'
16
16
  def version
17
17
  puts(Mdq::VERSION)
18
18
  end
19
19
 
20
- desc 'check', 'Check the software installation status'
20
+ desc 'check', 'Check the software installation status.'
21
21
  def check
22
22
  db = Mdq::DB.new
23
23
  puts "adb is installed: #{db.android_discoverable?}"
24
24
  puts "Xcode is installed: #{db.apple_discoverable?}"
25
25
  end
26
26
 
27
- desc 'devices', 'Show mobile devices'
27
+ desc 'devices', 'Show mobile devices.'
28
28
  method_option :android, desc: 'Show Android devices', default: true,
29
29
  type: :boolean
30
30
  method_option :apple, desc: 'Show Apple devices', default: true,
@@ -35,7 +35,7 @@ module Mdq
35
35
  puts(JSON.pretty_generate(Device.all.as_json))
36
36
  end
37
37
 
38
- desc 'apps', 'Show mobile apps'
38
+ desc 'apps', 'Show mobile apps.'
39
39
  method_option :android, desc: 'Show Android devices', default: true,
40
40
  type: :boolean
41
41
  method_option :apple, desc: 'Show Apple devices', default: true,
@@ -46,17 +46,27 @@ module Mdq
46
46
  puts(JSON.pretty_generate(App.all.as_json))
47
47
  end
48
48
 
49
- desc 'list', 'Show mobile devices or apps'
49
+ desc 'list', 'Show mobile devices or apps.'
50
+ method_option :android, desc: 'Show Android devices', default: true,
51
+ type: :boolean
52
+ method_option :apple, desc: 'Show Apple devices', default: true,
53
+ type: :boolean
50
54
  method_option :query, desc: 'SQL to filter devices or apps', aliases: '-q', required: true
51
55
  def list
52
56
  db = Mdq::DB.new
53
- db.get
54
- result = db.query(options['query'])
55
- puts(JSON.pretty_generate(result.as_json))
57
+ is_apps = db.query_contains_apps_table?(options[:query])
58
+ db.get(is_android: options[:android], is_apple: options[:apple], is_apps: is_apps)
59
+
60
+ begin
61
+ result = db.query(options['query'])
62
+ puts(JSON.pretty_generate(result.as_json))
63
+ rescue StandardError => e
64
+ warn e.message
65
+ end
56
66
  end
57
67
 
58
- desc 'cap', 'Path to save screenshots(Android only)'
59
- method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
68
+ desc 'cap', 'Path to save screenshots of the physical device.'
69
+ method_option :udid, desc: 'Specify the device UDID', aliases: '-u'
60
70
  method_option :output, desc: 'Save to file', aliases: '-o', required: true
61
71
  def cap
62
72
  db = Mdq::DB.new
@@ -73,7 +83,7 @@ module Mdq
73
83
  db.sim_screencap(options[:output], is_android: options[:platform] == 'android')
74
84
  end
75
85
 
76
- desc 'install', 'Installing the app(apk, apex, ipa)'
86
+ desc 'install', 'Installing the app(apk, apex, ipa).'
77
87
  method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
78
88
  method_option :input, desc: 'Path to the app file', aliases: '-i', required: true
79
89
  method_option :replace, desc: 'Replace the app if it is already installed', aliases: '-r', default: false,
@@ -84,7 +94,7 @@ module Mdq
84
94
  db.app_install(options[:input], options[:udid], options[:replace])
85
95
  end
86
96
 
87
- desc 'uninstall', 'Uninstalling the app'
97
+ desc 'uninstall', 'Uninstalling the app.'
88
98
  method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
89
99
  method_option :input, desc: 'Path to the app', aliases: '-i', required: true
90
100
  def uninstall
data/lib/mdq/db.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'mdq'
4
4
  require 'active_record'
5
5
  require 'fileutils'
6
+ require 'sql-parser'
6
7
 
7
8
  # Mdq
8
9
  module Mdq
@@ -30,24 +31,39 @@ module Mdq
30
31
  # クエリの実行
31
32
  def query(sql)
32
33
  ActiveRecord::Base.connection.execute(sql)
33
- rescue StandardError
34
- []
34
+ rescue StandardError => e
35
+ raise e
35
36
  end
36
37
 
37
38
  # 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.'
39
+ def device_screencap(output, udid = nil)
40
+ devices = if udid.nil?
41
+ Device.where(physical: true)
42
+ else
43
+ Device
44
+ .where('udid LIKE ?', "#{udid}%")
45
+ .where(physical: true)
46
+ end
47
+
48
+ if devices.empty?
49
+ warn 'Device not found.'
42
50
  return
43
51
  end
44
52
 
45
53
  FileUtils.mkdir_p(output)
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)
54
+
55
+ devices.each do |device|
56
+ file = "#{device.udid}-#{Time.now.strftime('%y%m%d-%H%M%S')}.png"
57
+
58
+ if device.android?
59
+ full_path = "/sdcard/#{file}"
60
+ adb_command("shell screencap -p #{full_path}", device.udid)
61
+ adb_command("pull #{full_path} #{output}", device.udid)
62
+ adb_command("shell rm #{full_path}", device.udid)
63
+ else
64
+ apple_command("device capture screenshot --destination #{output}/#{file}", device.udid)
65
+ end
66
+ end
51
67
  end
52
68
 
53
69
  def sim_screencap(output, is_android: true)
@@ -100,5 +116,31 @@ module Mdq
100
116
  puts output unless output.empty?
101
117
  warn error unless error.empty?
102
118
  end
119
+
120
+ # クエリにappsテーブルが含まれているかを判定する
121
+ def query_contains_apps_table?(query)
122
+ parser = SQLParser::Parser.new
123
+ ast = parser.scan_str(query)
124
+ find_tables(ast).uniq.include?('apps')
125
+ rescue StandardError
126
+ false
127
+ end
128
+
129
+ private
130
+
131
+ def find_tables(node)
132
+ tables = []
133
+ if node.is_a?(SQLParser::Statement::Table)
134
+ tables << node.name
135
+ elsif node.respond_to?(:each)
136
+ node.each { |child| tables += find_tables(child) }
137
+ elsif node.instance_variables.any?
138
+ node.instance_variables.each do |var|
139
+ val = node.instance_variable_get(var)
140
+ tables += find_tables(val)
141
+ end
142
+ end
143
+ tables
144
+ end
103
145
  end
104
146
  end
data/lib/mdq/discovery.rb CHANGED
@@ -154,7 +154,8 @@ module Mdq
154
154
  mac_address: mac_address,
155
155
  ip_address: ip_address,
156
156
  ipv6_address: ipv6_address.join(','),
157
- wifi_network: wifi_network
157
+ wifi_network: wifi_network,
158
+ physical: true
158
159
  })
159
160
 
160
161
  else
@@ -162,7 +163,8 @@ module Mdq
162
163
  udid: udid,
163
164
  serial_number: udid,
164
165
  authorized: false,
165
- platform: 'Android'
166
+ platform: 'Android',
167
+ physical: true
166
168
  })
167
169
  end
168
170
  end
@@ -181,6 +183,16 @@ module Mdq
181
183
  result['result']['devices'].each do |device|
182
184
  udid = device['hardwareProperties']['udid']
183
185
  total_disk = device['hardwareProperties']['internalStorageCapacity']
186
+
187
+ # 物理デバイスかどうか
188
+ # 判定できないときはnilにする
189
+ reality = device['hardwareProperties']['reality']
190
+ physical = if reality.nil?
191
+ nil
192
+ else
193
+ reality == 'physical'
194
+ end
195
+
184
196
  Device.create({
185
197
  udid: udid,
186
198
  serial_number: device['hardwareProperties']['serialNumber'],
@@ -192,7 +204,8 @@ module Mdq
192
204
  build_version: device['deviceProperties']['osVersionNumber'],
193
205
  build_id: device['deviceProperties']['osBuildUpdate'],
194
206
  total_disk: total_disk,
195
- human_readable_total_disk: number_to_human_size(total_disk, k)
207
+ human_readable_total_disk: number_to_human_size(total_disk, k),
208
+ physical: physical
196
209
  })
197
210
  end
198
211
 
@@ -274,6 +287,7 @@ ActiveRecord::Migration.create_table :devices do |t|
274
287
  t.string :platform
275
288
  t.string :marketing_name
276
289
  t.string :model
290
+ t.boolean :physical
277
291
  t.string :build_version
278
292
  t.string :build_id
279
293
  t.integer :battery_level
data/lib/mdq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mdq
4
- VERSION = '1.3.1'
4
+ VERSION = '1.5.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arthur87
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-05-25 00:00:00.000000000 Z
10
+ date: 2026-06-18 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rubocop
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: sql-parser
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
54
68
  - !ruby/object:Gem::Dependency
55
69
  name: thor
56
70
  requirement: !ruby/object:Gem::Requirement