hackmac 1.8.2 → 1.8.3

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.
data/README.md CHANGED
@@ -1,59 +1,105 @@
1
- # HackMac
1
+ # HackMac 🚀
2
2
 
3
- ## Description
4
-
5
- Some ruby tools for working with a Hackintosh, which also might be (partially)
6
- useful an a regular Mac.
3
+ ## Description 📝
7
4
 
8
5
  HackMac is a set of Ruby tools specifically designed for managing and
9
6
  customizing Hackintosh configurations. While primarily intended for users with
10
7
  Hackintosh setups, it may also be useful for ordinary Mac users who want to
11
8
  leverage its features for monitoring system performance using `gfxmon`.
12
9
 
13
- ## Tools
10
+ ## Tools 🛠️
14
11
 
15
- - `efi` is a tool to work with OpenCore EFI partitions, that is upgrading
16
- OpenCore and Kexts and commiting to its git repository.
17
- - `usb` can be used to create a bootable USB containing a MacOs release and
18
- uses an EFI partition cloned from a git repository.
19
- - `gfxmon` dispays performance statistics for your AMD GPU in the terminal,
20
- that is temperature, clock rate, fan rotations, memory and power usage as
21
- provided by MacOS, see the screenshot:
22
- ![gfxmon Screenshot](./img/gfxmon.png "gfxmon Screenshot")
12
+ ### `efi` - EFI Partition Management 📁
13
+ Manage OpenCore EFI partitions including:
14
+ - Upgrading OpenCore and kernel extensions (kexts) 🔧
15
+ - Committing changes to git repositories 💾
16
+ - Mounting/unmounting EFI volumes 📌
17
+ - Cloning EFI partitions between devices 🔄
23
18
 
24
- ## Installation
19
+ ### `usb` - Bootable USB Creator 🖥️
20
+ Create bootable USB drives for macOS installation with:
21
+ - Format USB device with GPT partition scheme 📊
22
+ - Create bootable installer using Apple's `createinstallmedia` ⚡
23
+ - Initialize git repository on EFI partition 📦
25
24
 
26
- You can use rubygems to fetch the gem and install it for you:
25
+ ### `gfxmon` - GPU Performance Monitor 🎮
26
+ Display real-time performance statistics for your GPU in the terminal including:
27
+ - Temperature, clock rates, fan rotations 🌡️
28
+ - Memory usage and power consumption ⚡
29
+ - Color-coded visualizations with ANSI terminal graphics 🎨
27
30
 
28
- # gem install hackmac
31
+ ![gfxmon Screenshot](./img/gfxmon.png "gfxmon Screenshot")
29
32
 
30
- You can also put this line into your Gemfile
33
+ ## Installation 📦
31
34
 
32
- gem 'hackmac'
35
+ ### Using RubyGems 💎
36
+ ```bash
37
+ gem install hackmac
38
+ ```
33
39
 
34
- # Configuration
40
+ ### Using Bundler 📦
41
+ Add to your Gemfile:
42
+ ```ruby
43
+ gem 'hackmac'
44
+ ```
35
45
 
36
- First start `efi` without arguments this will display the available commands,
37
- but also initializes a default configuration file in
38
- `~/.config/hackmac/hackmac.yml` to get you started. If you want work with
39
- multiple configuration files you can change the path by setting
46
+ ## Configuration ⚙️
40
47
 
48
+ First run `efi` without arguments to display available commands and initialize
49
+ the default configuration file at:
50
+ ```
51
+ ~/.config/hackmac/hackmac.yml
41
52
  ```
42
- $ export HACKMAC_CONFIG=~/config/hackmac/other.yml
53
+
54
+ To use a custom configuration file, set the environment variable:
55
+ ```bash
56
+ export HACKMAC_CONFIG=~/config/hackmac/other.yml
43
57
  ```
44
58
 
45
- in your shell.
59
+ ## Usage Examples 🎯
60
+
61
+ ### EFI Management 📁
62
+ ```bash
63
+ # Mount EFI partition
64
+ efi mount
65
+
66
+ # Clone EFI partitions
67
+ efi clone /dev/disk0s1 /dev/disk1s1
68
+
69
+ # Upgrade OpenCore
70
+ efi oc_upgrade
46
71
 
47
- ## Download
72
+ # Show kext versions
73
+ efi kexts
74
+ ```
75
+
76
+ ### GPU Monitoring 🎮
77
+ ```bash
78
+ # Real-time monitoring with 2-second updates
79
+ gfxmon -n 2
80
+
81
+ # Monitor specific metric
82
+ gfxmon -m "Temperature(C)"
83
+
84
+ # Output as JSON for scripting
85
+ gfxmon -j
86
+ ```
87
+
88
+ ### USB Creation 🖥️
89
+ ```bash
90
+ # Create bootable USB
91
+ usb /dev/disk2
92
+ ```
48
93
 
49
- The homepage of this library is located at
94
+ ## Download 🌐
50
95
 
51
- * https://github.com/flori/hackmac
96
+ The homepage of this library is located at:
97
+ https://github.com/flori/hackmac
52
98
 
53
- ## Author
99
+ ## Author 👨‍💻
54
100
 
55
101
  [Florian Frank](mailto:flori@ping.de)
56
102
 
57
- ## License
103
+ ## License 📄
58
104
 
59
- This software is licensed under the MIT license.
105
+ This software is licensed under the [MIT license](LICENSE).
data/Rakefile CHANGED
@@ -14,6 +14,8 @@ GemHadar do
14
14
  test_dir 'tests'
15
15
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble',
16
16
  'tags', '.bundle', '.DS_Store', '.byebug_history'
17
+ package_ignore '.gitignore', '.contexts'
18
+
17
19
  readme 'README.md'
18
20
 
19
21
  dependency 'tins', '~>1.14'
@@ -25,4 +27,6 @@ GemHadar do
25
27
  dependency 'search_ui'
26
28
  dependency 'hashie'
27
29
  development_dependency 'debug'
30
+
31
+ licenses << 'MIT'
28
32
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.2
1
+ 1.8.3
data/bin/efi CHANGED
@@ -1,9 +1,41 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # Hackmac EFI Management Tool
4
+ #
5
+ # This script provides comprehensive management capabilities for OpenCore EFI
6
+ # partitions including mounting/unmounting, cloning, kext management, OpenCore
7
+ # upgrades, and git operations.
8
+ #
9
+ # Features:
10
+ #
11
+ # - Mount/Unmount EFI partitions
12
+ # - Clone EFI partitions between devices
13
+ # - Manage kernel extensions (kexts) and their versions
14
+ # - Upgrade OpenCore bootloader to latest versions
15
+ # - Validate OpenCore configurations
16
+ # - Git integration for tracking EFI changes
17
+ #
18
+ # Usage: efi [command] [arguments]
19
+ # Run without arguments to see full help and available commands
20
+ #
21
+ # Configuration:
22
+ # Set HACKMAC_CONFIG to specify a custom config file path
23
+ # Defaults to ~/.config/hackmac/hackmac.yml
2
24
 
3
25
  require 'hackmac'
4
26
  include Hackmac
5
27
  include Utils
6
28
 
29
+ # The clone method performs a disk cloning operation between two volumes
30
+ #
31
+ # This method facilitates the cloning of data from one disk volume to another
32
+ # by first prompting the user for confirmation, then mounting both volumes,
33
+ # performing a dry-run of the rsync operation to show what would be copied, and
34
+ # finally executing the actual copy with deletion of extraneous files.
35
+ #
36
+ # @param from [ String ] the source disk identifier to clone from
37
+ # @param to [ String ] the target disk identifier to clone to
38
+ # @return [ void ] Returns nothing but performs system disk cloning operations
7
39
  def clone(from:, to:)
8
40
  ask("Cloning from #{from} to #{to} now? (y/n) ") or return
9
41
  x %{sudo mkdir -v "/Volumes/#{from}"}
@@ -18,10 +50,18 @@ def clone(from:, to:)
18
50
  x %{rsync -av --exclude ".*" --delete "/Volumes/#{from}/" "/Volumes/#{to}/"}
19
51
  end
20
52
 
53
+ # The usage method displays help information and command usage instructions
54
+ #
55
+ # This method outputs a formatted help message that describes the available
56
+ # commands and their arguments for the Hackmac tool. It provides default device
57
+ # names
58
+ # and explains how to configure the tool using environment variables.
59
+ #
60
+ # @return [ void ] Returns nothing but prints usage information to standard output
21
61
  def usage
22
62
  default_dev = device_name('main')
23
63
 
24
- puts <<~end
64
+ puts <<~EOT
25
65
 
26
66
  Usage #{File.basename($0)} [command] [arguments]
27
67
 
@@ -88,11 +128,21 @@ def usage
88
128
  Commits changes with git, passes arguments to commit command
89
129
  after "--".
90
130
 
91
- end
131
+ EOT
92
132
  end
93
133
 
94
- $config = Hackmac::Config.load
95
-
134
+ # The device_name method determines the appropriate device name based on the
135
+ # provided mount device identifier
136
+ #
137
+ # This method retrieves the device name by checking if a mount device
138
+ # identifier is provided. If no identifier is given, it returns the main device
139
+ # name from the configuration. If an identifier is provided, it looks up the
140
+ # corresponding device in the configuration and returns its name, falling back
141
+ # to the original identifier if not found
142
+ #
143
+ # @param mdev [ String, nil ] the mount device identifier to look up, or nil to use the main device
144
+ #
145
+ # @return [ String ] the resolved device name from configuration or the original identifier
96
146
  def device_name(mdev)
97
147
  case mdev
98
148
  when nil
@@ -106,6 +156,16 @@ def device_name(mdev)
106
156
  end
107
157
  end
108
158
 
159
+ # The git_args method processes command line arguments to determine the device
160
+ # name and default git arguments
161
+ #
162
+ # This method handles the parsing of command line arguments for git operations,
163
+ # identifying whether a device name is provided and managing the default
164
+ # arguments that should be used when none are specified
165
+ #
166
+ # @param default [ Array<String> ] the default git arguments to use when none are provided
167
+ #
168
+ # @return [ String ] the device name determined from the command line arguments
109
169
  def git_args(default:)
110
170
  mdev =
111
171
  if ARGV.first == '--'
@@ -120,22 +180,19 @@ def git_args(default:)
120
180
  mdev
121
181
  end
122
182
 
183
+ $config = Hackmac::Config.load
184
+
123
185
  bold_head = -> h { h.sub(/\A[a-z]/) { $&.upcase }.bold }
124
186
 
125
187
  case command = ARGV.shift
126
188
  when 'help', nil
127
189
  usage
128
190
  when 'mount'
129
- #if File.exist?('/Volumes/EFI')
130
- # raise "/Volumes/EFI already exists => Sort this out first."
131
- #end
132
191
  mdev = device_name(ARGV.shift)
133
192
  x %{sudo diskutil mount "#{mdev}"}
134
- # TODO symlink to /Volumes/mdev, mdev should be foo['MountPoint'] from efi boot
135
193
  when /\Aun?mount\z/
136
194
  mdev = device_name(ARGV.shift)
137
195
  x %{sudo diskutil unmount "#{mdev}"}
138
- # TODO remove /Volumes/mdev if it is a symlink
139
196
  when /\Adiff\z/
140
197
  mdev = git_args(default: %w[ --color --stat --cached ])
141
198
  x %{sudo diskutil mount "#{mdev}"}
@@ -161,9 +218,11 @@ when 'clone'
161
218
  when 'kexts'
162
219
  mdev = device_name(ARGV.shift)
163
220
  x %{sudo diskutil mount "#{mdev}"}
164
- on_efi = Dir["/Volumes/#{mdev}/#{$config.kext.efi_path}/*.kext"].map { |path|
221
+ on_efi = Dir["/Volumes/#{mdev}/#{$config.kext.efi_path}/*.kext"].map do |path|
165
222
  Kext.new(path: path, config: $config)
166
- }.sort_by(&:name)
223
+ rescue Errno::ENOENT
224
+ warn "#{path.to_s.inspect} has no info => Skipping."
225
+ end.compact.sort_by(&:name)
167
226
  puts 'EFI'.yellow.bold + " (#{mdev})".bold
168
227
  puts Tabulo::Table.new(on_efi, align_header: :left, border: :modern) { |t|
169
228
  t.add_column(:name, header_styler: bold_head)
data/bin/gfxmon CHANGED
@@ -1,4 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # GPU Performance Monitor
4
+ #
5
+ # A terminal-based tool for monitoring and visualizing GPU performance metrics
6
+ # in real-time. Displays system hardware statistics including temperature,
7
+ # clock speeds, memory usage, and power consumption with graphical
8
+ # representations.
9
+ #
10
+ # Features:
11
+ # - Real-time monitoring with customizable update intervals
12
+ # - Color-coded visualizations using ANSI terminal graphics
13
+ # - Support for multiple metric types (bytes, hertz, celsius, percentage)
14
+ # - Interactive search for performance metrics
15
+ # - JSON output support for integration with other tools
16
+ #
17
+ # Example:
18
+ # gfxmon # Real-time graph with metrics
19
+ # gfxmon -n 3 # Update every 3 seconds
20
+ # gfxmon -m "Temperature(C)" # Show specific metric
2
21
 
3
22
  require 'tins'
4
23
  include Tins::GO
@@ -16,8 +35,15 @@ include SearchUI
16
35
 
17
36
  $opts = go 'c:m:n:jlh', defaults: { ?s => true, ?n => 5 }
18
37
 
38
+ # The usage method displays command-line usage information and options
39
+ #
40
+ # This method prints a formatted help message to the standard output that
41
+ # describes how to use the command-line tool, including available options
42
+ # and their descriptions for controlling GPU performance data output
43
+ #
44
+ # @return [ Integer ] always returns 0 to indicate successful help display
19
45
  def usage
20
- puts <<~end
46
+ puts <<~EOT
21
47
  Usage: #{File.basename($0)} [OPTIONS]
22
48
 
23
49
  OPTIONS are
@@ -29,14 +55,30 @@ def usage
29
55
  -m METRIC output graph for performance METRIC
30
56
  -c COLOR output graph in this terminal COLOR (between 0 - 255)
31
57
 
32
- end
58
+ EOT
33
59
  0
34
60
  end
35
61
 
62
+ # The ps method retrieves performance statistics from the IORegistry
63
+ #
64
+ # This method accesses the PerformanceStatistics key in the IORegistry
65
+ # to obtain detailed hardware performance data and returns it as a hash
66
+ #
67
+ # @return [ Hash ] a hash containing the performance statistics data from the
68
+ # IORegistry
36
69
  def ps
37
70
  Hackmac::IOReg.new(key: 'PerformanceStatistics').as_hash
38
71
  end
39
72
 
73
+ # The list method displays a formatted key-value pair listing with colored
74
+ # output
75
+ #
76
+ # This method takes a hash of key-value pairs and formats them for display in
77
+ # the terminal, applying color coding to the keys and formatting the values
78
+ # according to derived formatters. It sorts the entries by key before
79
+ # displaying them.
80
+ #
81
+ # @param ps [ Hash ] a hash containing string keys and numeric or string values to be displayed
40
82
  def list(ps)
41
83
  max = ps.keys.max_by(&:size)&.size&.to_i
42
84
  include Hackmac::Graph::Formatters
@@ -46,6 +88,21 @@ def list(ps)
46
88
  }
47
89
  end
48
90
 
91
+ # The choose_metric method selects a metric from a provided hash based on user
92
+ # input or configuration
93
+ #
94
+ # This method attempts to determine the appropriate metric to use by first
95
+ # checking for a configured metric in the global options. If no metric is
96
+ # configured, it prompts the user to select from available metrics using an
97
+ # interactive search interface. The method validates that the selected metric
98
+ # exists in the provided hash and raises an error if the metric is not
99
+ # recognized.
100
+ #
101
+ # @param ps [ Hash ] a hash containing available metric names as keys
102
+ #
103
+ # @return [ String ] the name of the selected metric
104
+ #
105
+ # @raise [ RuntimeError ] if the specified metric is not found in the provided hash
49
106
  def choose_metric(ps)
50
107
  case metric = $opts[?m]
51
108
  when nil
@@ -73,6 +130,16 @@ def choose_metric(ps)
73
130
  fail "Metric #{metric} not known"
74
131
  end
75
132
 
133
+ # The derive_formatter method maps a metric string to an appropriate formatting
134
+ # method symbol
135
+ #
136
+ # This method takes a metric identifier string and determines the corresponding
137
+ # formatting strategy by matching against common metric patterns such as bytes,
138
+ # hertz, celsius, and percentage values
139
+ #
140
+ # @param metric [ String ] the metric identifier to derive formatting from
141
+ #
142
+ # @return [ Symbol ] the appropriate formatter method symbol for the given metric
76
143
  def derive_formatter(metric)
77
144
  case metric
78
145
  when /bytes/i
@@ -88,6 +155,18 @@ def derive_formatter(metric)
88
155
  end
89
156
  end
90
157
 
158
+ # The display_graph method creates and starts a graphical representation of
159
+ # system metrics
160
+ #
161
+ # This method initializes a graph visualization based on selected system
162
+ # metrics, configuring the display with appropriate formatting, color settings,
163
+ # and update intervals before beginning the continuous rendering process
164
+ #
165
+ # @return [ void ] Returns nothing but initiates the graphical display loop for system metrics
166
+ #
167
+ # @see Hackmac::Graph
168
+ # @see choose_metric
169
+ # @see derive_formatter
91
170
  def display_graph
92
171
  if metric = choose_metric(ps)
93
172
  sleep_duration = [ 1, ($opts[?n] || 10).to_i ].max
data/bin/usb CHANGED
@@ -1,17 +1,41 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # USB Installer Script
4
+ #
5
+ # This script prepares a USB drive for macOS installation by:
6
+ # - Formatting the USB device with GPT partition scheme
7
+ # - Creating a bootable installer using Apple's createinstallmedia tool
8
+ # - Mounting the EFI partition and initializing a git repository
9
+ #
10
+ # Example: usb /dev/disk2
11
+ #
12
+ # Requirements:
13
+ # - USB device must be at least 16GB
14
+ # - macOS installer package must be present in config
15
+ # - User must have administrator privileges
16
+ #
17
+ # Environment Variables:
18
+ # HACKMAC_CONFIG - Path to configuration file (default: ~/.config/hackmac/config.yml)
19
+ #
20
+ # This script performs destructive operations and should be used with caution.
2
21
 
3
22
  require 'hackmac'
4
23
  include Hackmac
5
24
  include Utils
6
25
 
26
+ # The usage method displays help information and exits the program
27
+ #
28
+ # This method prints a usage message to the standard output that includes
29
+ # the command name and available options, then terminates execution with
30
+ # a status code of 1
7
31
  def usage
8
- puts <<~end
32
+ puts <<~EOT
9
33
 
10
34
  Usage #{File.basename($0)} [USB DEVICE]
11
35
 
12
36
  Set HACKMAC_CONFIG to the config file, e. g. ~/.config/hackmac/foobar.yml
13
37
 
14
- end
38
+ EOT
15
39
  exit 1
16
40
  end
17
41
 
data/hackmac.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: hackmac 1.8.2 ruby lib
2
+ # stub: hackmac 1.8.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "hackmac".freeze
6
- s.version = "1.8.2".freeze
6
+ s.version = "1.8.3".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -13,15 +13,16 @@ Gem::Specification.new do |s|
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["efi".freeze, "gfxmon".freeze, "usb".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/hackmac.rb".freeze, "lib/hackmac/asset_tools.rb".freeze, "lib/hackmac/config.rb".freeze, "lib/hackmac/disks.rb".freeze, "lib/hackmac/github_source.rb".freeze, "lib/hackmac/graph.rb".freeze, "lib/hackmac/graph/display.rb".freeze, "lib/hackmac/ioreg.rb".freeze, "lib/hackmac/kext.rb".freeze, "lib/hackmac/kext_upgrader.rb".freeze, "lib/hackmac/oc.rb".freeze, "lib/hackmac/oc_upgrader.rb".freeze, "lib/hackmac/oc_validator.rb".freeze, "lib/hackmac/plist.rb".freeze, "lib/hackmac/url_download.rb".freeze, "lib/hackmac/utils.rb".freeze, "lib/hackmac/version.rb".freeze]
16
- s.files = [".gitignore".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/efi".freeze, "bin/gfxmon".freeze, "bin/usb".freeze, "hackmac.gemspec".freeze, "img/gfxmon.png".freeze, "lib/hackmac.rb".freeze, "lib/hackmac/asset_tools.rb".freeze, "lib/hackmac/config.rb".freeze, "lib/hackmac/disks.rb".freeze, "lib/hackmac/github_source.rb".freeze, "lib/hackmac/graph.rb".freeze, "lib/hackmac/graph/display.rb".freeze, "lib/hackmac/hackmac.yml".freeze, "lib/hackmac/ioreg.rb".freeze, "lib/hackmac/kext.rb".freeze, "lib/hackmac/kext_upgrader.rb".freeze, "lib/hackmac/oc.rb".freeze, "lib/hackmac/oc_upgrader.rb".freeze, "lib/hackmac/oc_validator.rb".freeze, "lib/hackmac/plist.rb".freeze, "lib/hackmac/url_download.rb".freeze, "lib/hackmac/utils.rb".freeze, "lib/hackmac/version.rb".freeze]
16
+ s.files = [".context/code_comment.rb".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/efi".freeze, "bin/gfxmon".freeze, "bin/usb".freeze, "hackmac.gemspec".freeze, "img/gfxmon.png".freeze, "lib/hackmac.rb".freeze, "lib/hackmac/asset_tools.rb".freeze, "lib/hackmac/config.rb".freeze, "lib/hackmac/disks.rb".freeze, "lib/hackmac/github_source.rb".freeze, "lib/hackmac/graph.rb".freeze, "lib/hackmac/graph/display.rb".freeze, "lib/hackmac/hackmac.yml".freeze, "lib/hackmac/ioreg.rb".freeze, "lib/hackmac/kext.rb".freeze, "lib/hackmac/kext_upgrader.rb".freeze, "lib/hackmac/oc.rb".freeze, "lib/hackmac/oc_upgrader.rb".freeze, "lib/hackmac/oc_validator.rb".freeze, "lib/hackmac/plist.rb".freeze, "lib/hackmac/url_download.rb".freeze, "lib/hackmac/utils.rb".freeze, "lib/hackmac/version.rb".freeze]
17
17
  s.homepage = "http://github.com/flori/hackmac".freeze
18
+ s.licenses = ["MIT".freeze]
18
19
  s.rdoc_options = ["--title".freeze, "Hackmac - Some useful tools for working with a Hackintosh".freeze, "--main".freeze, "README.md".freeze]
19
20
  s.rubygems_version = "3.6.9".freeze
20
21
  s.summary = "Some useful tools for working with a Hackintosh".freeze
21
22
 
22
23
  s.specification_version = 4
23
24
 
24
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.20".freeze])
25
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.6".freeze])
25
26
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
26
27
  s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.14".freeze])
27
28
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.10".freeze])
@@ -1,7 +1,35 @@
1
1
  module Hackmac
2
+ # A module that provides utility methods for creating temporary directories
3
+ # and decompressing files.
4
+ #
5
+ # The AssetTools module offers helper methods designed to simplify common
6
+ # tasks when working with temporary file operations and compressed assets. It
7
+ # includes functionality for isolating code execution within temporary
8
+ # directories and extracting various compressed file formats.
9
+ #
10
+ # @example
11
+ # include Hackmac::AssetTools
12
+ #
13
+ # isolate do |dir|
14
+ # # Code executed within temporary directory
15
+ # end
16
+ #
17
+ # decompress('archive.tar.gz')
2
18
  module AssetTools
3
19
  private
4
20
 
21
+ # The isolate method creates a temporary directory and yields control to a
22
+ # block within that directory context.
23
+ #
24
+ # This method establishes a temporary working directory using Dir.mktmpdir,
25
+ # changes the current working directory to that location, and then executes
26
+ # the provided block within that context. After the block completes, it
27
+ # ensures proper cleanup of the temporary directory.
28
+ #
29
+ # @param block [ Block ] the block to execute within the temporary
30
+ # directory context
31
+ #
32
+ # @return [ Object ] the return value of the yielded block
5
33
  def isolate
6
34
  Dir.mktmpdir do |dir|
7
35
  cd dir do
@@ -10,6 +38,20 @@ module Hackmac
10
38
  end
11
39
  end
12
40
 
41
+ # The decompress method extracts compressed files in either ZIP or tar.gz
42
+ # format
43
+ #
44
+ # This method takes a filename and attempts to decompress it using the
45
+ # appropriate system command based on the file extension. It provides
46
+ # visual feedback during the decompression process and raises an error if
47
+ # the operation fails.
48
+ #
49
+ # @param name [ String ] the path to the compressed file to be decompressed
50
+ #
51
+ # @return [ void ] Returns nothing, but performs system decompression operations
52
+ #
53
+ # @raise [ RuntimeError ] raised when the file extension is not supported or
54
+ # decompression commands fail
13
55
  def decompress(name)
14
56
  print "Decompressing #{name.inspect}…"
15
57
  case name
@@ -22,6 +64,5 @@ module Hackmac
22
64
  end
23
65
  puts "done!"
24
66
  end
25
-
26
67
  end
27
68
  end
@@ -5,6 +5,22 @@ require 'pathname'
5
5
  require 'term/ansicolor'
6
6
 
7
7
  module Hackmac
8
+ # A module that provides configuration loading and management functionality
9
+ # for Hackmac
10
+ #
11
+ # The Config module handles the initialization and retrieval of Hackmac's
12
+ # configuration settings from specified files or default locations. It
13
+ # manages configuration directories, creates default configuration files when
14
+ # needed, and loads configurations into memory for use throughout the
15
+ # application.
16
+ #
17
+ # @example
18
+ # Hackmac::Config.load
19
+ # # Loads the default configuration file
20
+ #
21
+ # @example
22
+ # Hackmac::Config.load(path: '/custom/config/path.yml')
23
+ # # Loads a custom configuration file from the specified path
8
24
  module Config
9
25
  extend FileUtils
10
26
  extend ComplexConfig::Provider::Shortcuts
@@ -12,6 +28,22 @@ module Hackmac
12
28
 
13
29
  DEFAULT = File.read(File.join(File.dirname(__FILE__), 'hackmac.yml'))
14
30
 
31
+ # Loads the Hackmac configuration from the specified path or default
32
+ # location
33
+ #
34
+ # This method initializes the configuration system by reading from a
35
+ # specified file path or using the default configuration file location. It
36
+ # ensures the configuration directory exists, sets up the configuration
37
+ # provider's directory, creates a default configuration file if one doesn't
38
+ # exist, and loads the configuration into memory for use throughout the
39
+ # application.
40
+ #
41
+ # @param path [ String ] the file path to load the configuration from, defaults
42
+ # to the value of the HACKMAC_CONFIG environment variable or the default
43
+ # location ~/.config/hackmac/hackmac.yml
44
+ #
45
+ # @return [ ComplexConfig::Provider ] the loaded configuration provider object
46
+ # that can be used to access configuration values
15
47
  def self.load(path: ENV.fetch('HACKMAC_CONFIG', '~/.config/hackmac/hackmac.yml'))
16
48
  path = Pathname.new(path).expand_path
17
49
  mkdir_p path.dirname