mdq 0.5.2 → 1.0.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: e6f15383d8943cba2f10e8204a31fde8117580ad57a94d0141ad898a5ed50b6a
4
- data.tar.gz: ff937fc11de10ff1a1f97176a19cafa0aea59bf3cfeb18dd183ff79b5592868c
3
+ metadata.gz: 29fbbd7bc987bc45f23473fff290c05f458f9677c0f95739c6cfab4ea0e4da13
4
+ data.tar.gz: 7797f6cdaad6c791717a83bfa5bfb67d5a1f485bc84e8855a6e3f91adc26251b
5
5
  SHA512:
6
- metadata.gz: 10a89282279e49ebf393d06d9af0e2d1483a958901f3f40b0a321e2c59f0ff16e9388f1d186f7af2c75556d33994e14f9228b258c7453dd819c7fbb36c509006
7
- data.tar.gz: '09a80da76956894938b457d9c4ff1ab5d24093d84f5069e7e43ff79ecf3952c3d57888f16eaf75845cd3b51b6e1cdaf17dc8fc731d99f36fa2fb979333535c4f'
6
+ metadata.gz: 6fa1379783a969a874b20beb37b02d7ea7134f55f4cfc41f69c7b41ad8e3ab1f293602e8aa3cc2a8557d40fe5c18a08bfee49c16e4e7aa84241aac161abadf30
7
+ data.tar.gz: 7612066bfa36a5702c7194da49f1d562bed37ddbcf0537e510dfcb4260baab57047743af94e8b734cdcd001b9d94bcd704c557d2d6552a36c7d6835a28d3ceb8
data/README.base.md CHANGED
@@ -22,6 +22,23 @@ Check the software installation status.
22
22
  $ mdq check
23
23
  ```
24
24
 
25
+ ## Devices
26
+
27
+ Show mobile devices.
28
+
29
+ ```
30
+ $ mdq devices
31
+ ```
32
+
33
+ ## Apss
34
+
35
+ Show apps.
36
+
37
+ ```
38
+ $ mdq apps
39
+ ```
40
+
41
+
25
42
  ## List
26
43
 
27
44
  It's easy to use.
@@ -122,20 +139,20 @@ $ mdq list -q='select * from apps'
122
139
  Take a screenshot on Android.
123
140
 
124
141
  ```
125
- $ mdq list --cap='/Users/xxxxx/'
142
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
126
143
  ```
127
144
 
128
145
  Install the app.
129
146
 
130
147
  ```
131
- $ mdq list --install='/Users/xxxxx/example.apk'
132
- $ mdq list --install='/Users/xxxxx/example.ipa'
148
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
149
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
133
150
  ```
134
151
 
135
152
  Uninstall the app.
136
153
 
137
154
  ```
138
- $ mdq list --uninstall='com.example.app'
155
+ $ mdq uninstall -i='com.example.app' -u='UDID'
139
156
  ```
140
157
 
141
158
 
data/README.ja.md CHANGED
@@ -17,6 +17,23 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
+ ## Devices
21
+
22
+ Show mobile devices.
23
+
24
+ ```
25
+ $ mdq devices
26
+ ```
27
+
28
+ ## Apss
29
+
30
+ Show apps.
31
+
32
+ ```
33
+ $ mdq apps
34
+ ```
35
+
36
+
20
37
  ## List
21
38
 
22
39
  It's easy to use.
@@ -117,20 +134,20 @@ $ mdq list -q='select * from apps'
117
134
  Take a screenshot on Android.
118
135
 
119
136
  ```
120
- $ mdq list --cap='/Users/xxxxx/'
137
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
121
138
  ```
122
139
 
123
140
  Install the app.
124
141
 
125
142
  ```
126
- $ mdq list --install='/Users/xxxxx/example.apk'
127
- $ mdq list --install='/Users/xxxxx/example.ipa'
143
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
144
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
128
145
  ```
129
146
 
130
147
  Uninstall the app.
131
148
 
132
149
  ```
133
- $ mdq list --uninstall='com.example.app'
150
+ $ mdq uninstall -i='com.example.app' -u='UDID'
134
151
  ```
135
152
 
136
153
 
data/README.md CHANGED
@@ -17,6 +17,23 @@ Check the software installation status.
17
17
  $ mdq check
18
18
  ```
19
19
 
20
+ ## Devices
21
+
22
+ Show mobile devices.
23
+
24
+ ```
25
+ $ mdq devices
26
+ ```
27
+
28
+ ## Apss
29
+
30
+ Show apps.
31
+
32
+ ```
33
+ $ mdq apps
34
+ ```
35
+
36
+
20
37
  ## List
21
38
 
22
39
  It's easy to use.
@@ -117,20 +134,20 @@ $ mdq list -q='select * from apps'
117
134
  Take a screenshot on Android.
118
135
 
119
136
  ```
120
- $ mdq list --cap='/Users/xxxxx/'
137
+ $ mdq cap -o='/Users/xxxxx/' -u='UDID'
121
138
  ```
122
139
 
123
140
  Install the app.
124
141
 
125
142
  ```
126
- $ mdq list --install='/Users/xxxxx/example.apk'
127
- $ mdq list --install='/Users/xxxxx/example.ipa'
143
+ $ mdq install -i='/Users/xxxxx/example.apk' -u='UDID'
144
+ $ mdq install -i=='/Users/xxxxx/example.ipa' -u='UDID'
128
145
  ```
129
146
 
130
147
  Uninstall the app.
131
148
 
132
149
  ```
133
- $ mdq list --uninstall='com.example.app'
150
+ $ mdq uninstall -i='com.example.app' -u='UDID'
134
151
  ```
135
152
 
136
153
 
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'
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, 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(apk, ipa)'
79
+ method_option :udid, desc: 'Specify the device UDID', aliases: '-u', required: true
80
+ method_option :input, desc: 'Path to the app file', 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,88 @@ 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
+ puts '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
+ file_error_message = 'Invalid file format. Please provide an .apk file for Android or an .ipa file for iOS.'
56
+ unless File.exist?(input)
57
+ puts file_error_message
58
+ return
59
+ end
55
60
 
56
- { command: 'install', udid: udid, result: output }
61
+ device = Device.find_by(udid: udid)
62
+ if device.nil?
63
+ puts 'Device not found.'
64
+ return
65
+ end
66
+
67
+ if device.android? && input.end_with?('.apk')
68
+ if is_replace
69
+ adb_command("install -r #{input}", udid)
70
+ else
71
+ adb_command("install #{input}", udid)
72
+ end
73
+ elsif !device.android? && input.end_with?('.ipa')
74
+ apple_command("device install app #{input}", udid)
75
+ else
76
+ puts file_error_message
77
+ end
57
78
  end
58
79
 
59
80
  # Appをアンインストールする
60
- def app_uninstall(input, udid, is_android)
61
- if is_android
62
- output, = adb_command("uninstall #{input}", udid)
63
- else
64
- output, = apple_command("device uninstall app #{input}", udid)
81
+ def app_uninstall(input, udid)
82
+ device = Device.find_by(udid: udid)
83
+ if device.nil?
84
+ puts 'Device not found.'
85
+ return
65
86
  end
66
87
 
67
- { command: 'uninstall', udid: udid, result: output }
88
+ if device.android?
89
+ adb_command("uninstall #{input}", udid)
90
+ else
91
+ apple_command("device uninstall app #{input}", udid)
92
+ end
68
93
  end
69
94
  end
70
95
  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.0'
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.0
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-01 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