├── .editorconfig ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── build.rs ├── script └── package ├── src ├── cli.rs ├── main.rs └── messages.rs └── tests ├── assets ├── defaults-escaped.yml └── defaults.yml └── integration.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.sh] 15 | switch_case_indent = true 16 | 17 | [*.{yaml,yml}] 18 | indent_size = 2 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target 4 | **/*.rs.bk 5 | 6 | 7 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 8 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 9 | # Cargo.lock 10 | 11 | # These are backup files generated by rustfmt 12 | **/*.rs.bk 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | sudo: false 3 | 4 | env: TARGET=x86_64-apple-darwin 5 | os: osx 6 | before_install: 7 | - rustup component add clippy-preview 8 | script: 9 | - cargo build --verbose --all 10 | - cargo clippy -- -D warnings 11 | - cargo test --verbose 12 | - cargo build --release --target "$TARGET" --locked 13 | matrix: 14 | allow_failures: 15 | - rust: nightly 16 | fast_finish: true 17 | include: 18 | - name: 'Rust: beta' 19 | rust: beta 20 | - name: 'Rust: nightly' 21 | rust: nightly 22 | allow_failures: true 23 | - name: 'Rust: stable' 24 | rust: stable 25 | before_deploy: 26 | - script/package "$TARGET" "apply-user-defaults-$TRAVIS_TAG-$TARGET" 27 | deploy: 28 | provider: releases 29 | api_key: 30 | secure: aVjO/V4gSIuYRZItd68Q2eaIobSJiX5GgePClTcVzfJQysqgDZdIOh+j4aE9SWL2GKy+3e3tMRUL+2ArLjTHKCn0j8VyA15vLPVXSKMQ6h4bhlHO+i5YDw95MrsyoSEKByqq8DO+1qzagX1lvi55+wBsFm7terCh98EHO9HLqKrRljblR+g1ycZ2qcYgRgo2EhBRQvOiJgpSYjEMqvAmViS8M3pjG2mxE1ZRfOj3CHEzecQtZ8lhMKYKs5v75r77WE3EpKyG3WpbjHMxh4m30I7KH0J6zZScDzcVt72TUPB1J/l/BnJjLrbek8tQM4OcegIYkXR7BaEJl1T7buv3VakpZoMXD9rQ8M1QDljj71FHfw44TEXhmx5J88oVtmPuIlR0OWtHvv8Avq1WdOjI2i2ITXJ/WpVYdRkFgozYFWYeBrryqje60chw+9kVdlljClWjQrOZVJxYESzKbQx7KCkA4uEJdTXuMrv9IzPSm8N67uYhJnoqY8OOgCCNB0Rg7VFro2jW3xGPRefg+fVpZuRZN0wXKKtepD7d8SaHUul3skEKn88O8nXAqNQPE4bkGbTVUBxRB2EAlCSebLSnxtujILjDlW4yOsydxAJCOqfJR5w0ZUHjZLVnoPg58sotaDc1T4Nn/cUBHNh2Zex83nPODP3HdOsu9XE2cUWdSpE= 31 | file: apply-user-defaults-$TRAVIS_TAG-$TARGET.tar.gz 32 | skip_cleanup: true 33 | on: 34 | repo: zero-sh/apply-user-defaults 35 | branch: master 36 | tags: true 37 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 - 2023-08-24 9 | 10 | ### Added 11 | - Added support for Apple Silicon. 12 | 13 | ## 0.1.2 - 2019-01-09 14 | 15 | ### Fixed 16 | - Updated to use absolute path when invoking defaults command. 17 | - Updated dependencies to latest versions. 18 | 19 | ## 0.1.1 - 2019-12-14 20 | 21 | ### Added 22 | - Added support for dry-run flag. 23 | 24 | ### Fixed 25 | - Fixed various warnings from clippy linter. 26 | 27 | ## 0.1.0 - 2019-12-12 28 | 29 | - Initial release. 30 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.6" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "ansi_term" 16 | version = "0.11.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 19 | dependencies = [ 20 | "winapi", 21 | ] 22 | 23 | [[package]] 24 | name = "apply-user-defaults" 25 | version = "0.2.0" 26 | dependencies = [ 27 | "assert_cli", 28 | "clap", 29 | "colored", 30 | "lazy_static", 31 | "regex", 32 | "yaml-rust", 33 | ] 34 | 35 | [[package]] 36 | name = "assert_cli" 37 | version = "0.6.3" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "a29ab7c0ed62970beb0534d637a8688842506d0ff9157de83286dacd065c8149" 40 | dependencies = [ 41 | "colored", 42 | "difference", 43 | "environment", 44 | "failure", 45 | "failure_derive", 46 | "serde_json", 47 | ] 48 | 49 | [[package]] 50 | name = "atty" 51 | version = "0.2.14" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 54 | dependencies = [ 55 | "hermit-abi", 56 | "libc", 57 | "winapi", 58 | ] 59 | 60 | [[package]] 61 | name = "backtrace" 62 | version = "0.3.40" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" 65 | dependencies = [ 66 | "backtrace-sys", 67 | "cfg-if", 68 | "libc", 69 | "rustc-demangle", 70 | ] 71 | 72 | [[package]] 73 | name = "backtrace-sys" 74 | version = "0.1.32" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" 77 | dependencies = [ 78 | "cc", 79 | "libc", 80 | ] 81 | 82 | [[package]] 83 | name = "bitflags" 84 | version = "1.2.1" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 87 | 88 | [[package]] 89 | name = "cc" 90 | version = "1.0.50" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" 93 | 94 | [[package]] 95 | name = "cfg-if" 96 | version = "0.1.10" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 99 | 100 | [[package]] 101 | name = "clap" 102 | version = "2.33.0" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" 105 | dependencies = [ 106 | "ansi_term", 107 | "atty", 108 | "bitflags", 109 | "strsim", 110 | "textwrap", 111 | "unicode-width", 112 | ] 113 | 114 | [[package]] 115 | name = "colored" 116 | version = "1.9.1" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "f930f8b286023ed451756fe2527d73484d667adf9e905e9932e81d52996a343a" 119 | dependencies = [ 120 | "atty", 121 | "lazy_static", 122 | "winapi", 123 | ] 124 | 125 | [[package]] 126 | name = "difference" 127 | version = "2.0.0" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" 130 | 131 | [[package]] 132 | name = "environment" 133 | version = "0.1.1" 134 | source = "registry+https://github.com/rust-lang/crates.io-index" 135 | checksum = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee" 136 | 137 | [[package]] 138 | name = "failure" 139 | version = "0.1.6" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" 142 | dependencies = [ 143 | "backtrace", 144 | "failure_derive", 145 | ] 146 | 147 | [[package]] 148 | name = "failure_derive" 149 | version = "0.1.6" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" 152 | dependencies = [ 153 | "proc-macro2", 154 | "quote", 155 | "syn", 156 | "synstructure", 157 | ] 158 | 159 | [[package]] 160 | name = "hermit-abi" 161 | version = "0.1.6" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" 164 | dependencies = [ 165 | "libc", 166 | ] 167 | 168 | [[package]] 169 | name = "itoa" 170 | version = "0.4.4" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" 173 | 174 | [[package]] 175 | name = "lazy_static" 176 | version = "1.4.0" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 179 | 180 | [[package]] 181 | name = "libc" 182 | version = "0.2.66" 183 | source = "registry+https://github.com/rust-lang/crates.io-index" 184 | checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" 185 | 186 | [[package]] 187 | name = "linked-hash-map" 188 | version = "0.5.2" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" 191 | 192 | [[package]] 193 | name = "memchr" 194 | version = "2.2.1" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 197 | 198 | [[package]] 199 | name = "proc-macro2" 200 | version = "1.0.7" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" 203 | dependencies = [ 204 | "unicode-xid", 205 | ] 206 | 207 | [[package]] 208 | name = "quote" 209 | version = "1.0.2" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" 212 | dependencies = [ 213 | "proc-macro2", 214 | ] 215 | 216 | [[package]] 217 | name = "regex" 218 | version = "1.3.1" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" 221 | dependencies = [ 222 | "aho-corasick", 223 | "memchr", 224 | "regex-syntax", 225 | "thread_local", 226 | ] 227 | 228 | [[package]] 229 | name = "regex-syntax" 230 | version = "0.6.12" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" 233 | 234 | [[package]] 235 | name = "rustc-demangle" 236 | version = "0.1.16" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" 239 | 240 | [[package]] 241 | name = "ryu" 242 | version = "1.0.2" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" 245 | 246 | [[package]] 247 | name = "serde" 248 | version = "1.0.104" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" 251 | 252 | [[package]] 253 | name = "serde_json" 254 | version = "1.0.44" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" 257 | dependencies = [ 258 | "itoa", 259 | "ryu", 260 | "serde", 261 | ] 262 | 263 | [[package]] 264 | name = "strsim" 265 | version = "0.8.0" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 268 | 269 | [[package]] 270 | name = "syn" 271 | version = "1.0.13" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | checksum = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" 274 | dependencies = [ 275 | "proc-macro2", 276 | "quote", 277 | "unicode-xid", 278 | ] 279 | 280 | [[package]] 281 | name = "synstructure" 282 | version = "0.12.3" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" 285 | dependencies = [ 286 | "proc-macro2", 287 | "quote", 288 | "syn", 289 | "unicode-xid", 290 | ] 291 | 292 | [[package]] 293 | name = "textwrap" 294 | version = "0.11.0" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 297 | dependencies = [ 298 | "unicode-width", 299 | ] 300 | 301 | [[package]] 302 | name = "thread_local" 303 | version = "0.3.6" 304 | source = "registry+https://github.com/rust-lang/crates.io-index" 305 | checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 306 | dependencies = [ 307 | "lazy_static", 308 | ] 309 | 310 | [[package]] 311 | name = "unicode-width" 312 | version = "0.1.7" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" 315 | 316 | [[package]] 317 | name = "unicode-xid" 318 | version = "0.2.0" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" 321 | 322 | [[package]] 323 | name = "winapi" 324 | version = "0.3.8" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 327 | dependencies = [ 328 | "winapi-i686-pc-windows-gnu", 329 | "winapi-x86_64-pc-windows-gnu", 330 | ] 331 | 332 | [[package]] 333 | name = "winapi-i686-pc-windows-gnu" 334 | version = "0.4.0" 335 | source = "registry+https://github.com/rust-lang/crates.io-index" 336 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 337 | 338 | [[package]] 339 | name = "winapi-x86_64-pc-windows-gnu" 340 | version = "0.4.0" 341 | source = "registry+https://github.com/rust-lang/crates.io-index" 342 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 343 | 344 | [[package]] 345 | name = "yaml-rust" 346 | version = "0.4.3" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | checksum = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" 349 | dependencies = [ 350 | "linked-hash-map", 351 | ] 352 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "apply-user-defaults" 3 | version = "0.2.0" 4 | authors = ["Michael Sanders "] 5 | description = "A small utility to set macOS user defaults declaratively from a YAML file." 6 | repository = "https://github.com/zero-sh/apply-user-defaults" 7 | readme = "README.md" 8 | license = "MIT OR Apache-2.0" 9 | build = "build.rs" 10 | edition = "2018" 11 | keywords = ["macos", "user", "defaults", "declarative", "yaml"] 12 | categories = [ 13 | "command-line-utilities", 14 | "config", 15 | "os::macos-apis", 16 | ] 17 | 18 | 19 | [dependencies] 20 | colored = "~1.9.0" 21 | lazy_static = "~1.4.0" 22 | regex = "~1.3.0" 23 | yaml-rust = "~0.4.0" 24 | 25 | [dev-dependencies] 26 | assert_cli = "~0.6.0" 27 | 28 | [dependencies.clap] 29 | version = "~2.33.0" 30 | default-features = false 31 | features = ["color", "suggestions"] 32 | 33 | [build-dependencies.clap] 34 | version = "~2.33.0" 35 | default-features = false 36 | features = ["color", "suggestions"] 37 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Michael Sanders. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright 2019 Michael Sanders. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/zero-sh/apply-user-defaults.svg?branch=master)](https://travis-ci.org/zero-sh/apply-user-defaults) 2 | ![License](https://img.shields.io/crates/l/apply-user-defaults.svg) 3 | [![Crates.io](https://img.shields.io/crates/v/apply-user-defaults.svg)](https://crates.io/crates/apply-user-defaults) 4 | 5 | # apply-user-defaults 6 | 7 | `apply-user-defaults` is a small utility to set macOS user defaults 8 | declaratively from a YAML file. 9 | 10 | ## Usage 11 | 12 | To use, simply structure a YAML file like the following: 13 | 14 | ```yaml 15 | com.apple.dock: 16 | # System Preferences > Dock > Automatically hide and show the Dock. 17 | autohide: true 18 | 19 | # System Preferences > Dock > Minimize windows using: Scale effect. 20 | mineffect: "scale" 21 | 22 | # System Preferences > Dock > Show indicators for open applications. 23 | show-process-indicators: false 24 | 25 | # System Preferences > Dock > Size. 26 | tilesize: 72 27 | ``` 28 | 29 | Then apply it using: 30 | 31 | ```sh 32 | $ apply-user-defaults path-to-file.yaml 33 | ``` 34 | 35 | You can also see what commands are being run by enabling verbose output: 36 | 37 | ```sh 38 | $ apply-user-defaults path-to-file.yaml --verbose 39 | ==> defaults write com.apple.dock autohide -bool true 40 | ==> defaults write com.apple.dock mineffect -string scale 41 | ==> defaults write com.apple.dock show-process-indicators -bool false 42 | ==> defaults write com.apple.dock tilesize -int 72 43 | Success! Applied defaults. 44 | ``` 45 | 46 | ## Template Expansion 47 | 48 | Environment variables can also be included using shell parameter expansion 49 | syntax. For example: 50 | 51 | ```yaml 52 | com.apple.finder: 53 | # Finder > Preferences > New Finder windows show > Home directory. 54 | NewWindowTargetPath: "file://${HOME}" 55 | ``` 56 | 57 | will evaluate to: 58 | 59 | ```sh 60 | defaults write com.apple.finder NewWindowTargetPath -string "file://$HOME" 61 | ``` 62 | 63 | where `$HOME` is the value contained in the `HOME` environment variable. 64 | 65 | This only applies when the string in the YAML file begins with a dollar sign and 66 | is wrapped in braces (just using `$HOME` won't work). 67 | 68 | To disable, you may pass the flag `--no-env` or escape the dollar sign, e.g. 69 | `'\\${VALUE}'`. 70 | 71 | ## Installation 72 | 73 | Pre-compiled binaries are available on the [releases 74 | page](https://github.com/zero-sh/apply-user-defaults/releases). 75 | 76 | ### Homebrew 77 | 78 | If you're using Homebrew, you can install with a custom tap: 79 | 80 | ```sh 81 | $ brew install zero-sh/tap/apply-user-defaults 82 | ``` 83 | 84 | ### Cargo Install 85 | 86 | To install via Cargo, run: 87 | 88 | ```sh 89 | $ cargo install apply-user-defaults 90 | ``` 91 | 92 | ### Building from Source 93 | 94 | To build from source: 95 | 96 | ```sh 97 | $ git clone https://github.com/zero-sh/apply-user-defaults.git 98 | $ cd apply-user-defaults 99 | $ cargo run -- path-to-file.yml --verbose 100 | ``` 101 | 102 | ## License 103 | 104 | This project is licensed under either the [Apache-2.0](LICENSE-APACHE) or 105 | [MIT](LICENSE-MIT) license, at your option. 106 | 107 | Unless you explicitly state otherwise, any contribution intentionally submitted 108 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 109 | dual licensed as above, without any additional terms or conditions. 110 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use clap::Shell; 2 | use std::{env,path}; 3 | use std::fs::File; 4 | 5 | include!("src/cli.rs"); 6 | 7 | fn main() { 8 | let outdir = env::var_os("OUT_DIR").unwrap(); 9 | let mut app = build_cli(); 10 | 11 | // Create dummy file to allow us to find this directory later via CI. 12 | let stamp_path = path::Path::new(&outdir).join("apply-user-defaults-stamp"); 13 | if let Err(err) = File::create(&stamp_path) { 14 | panic!("Failed to write {}: {}", stamp_path.display(), err); 15 | } 16 | 17 | app.gen_completions("apply-user-defaults", Shell::Bash, &outdir); 18 | app.gen_completions("apply-user-defaults", Shell::Fish, &outdir); 19 | app.gen_completions("apply-user-defaults", Shell::Zsh, &outdir); 20 | } 21 | -------------------------------------------------------------------------------- /script/package: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -o errexit -o nounset 3 | 4 | TARGET="$1" 5 | PACKAGE_NAME="$2" 6 | 7 | # Finds Cargo's `OUT_DIR` directory from the most recent build. 8 | # 9 | # This requires one parameter corresponding to the target directory to search 10 | # for the build output. 11 | # 12 | # See https://github.com/BurntSushi/ripgrep/blob/5ce2d73/ci/utils.sh#L5 13 | cargo_out_dir() { 14 | # This works by finding the most recent stamp file, which is produced by 15 | # our build script. 16 | find "$1" -name apply-user-defaults-stamp -print0 | 17 | xargs -0 ls -t | 18 | head -n1 | 19 | xargs dirname 20 | } 21 | 22 | mkdir -p "$PACKAGE_NAME" 23 | mkdir -p "$PACKAGE_NAME/complete" 24 | cp "target/$TARGET/release/apply-user-defaults" "$PACKAGE_NAME/" 25 | cp CHANGELOG.md README.md LICENSE-MIT LICENSE-APACHE "$PACKAGE_NAME/" 26 | 27 | COMPLETION_OUT_DIR="$(cargo_out_dir "target/$TARGET")" 28 | cp "$COMPLETION_OUT_DIR/_apply-user-defaults" "$PACKAGE_NAME/complete/" 29 | cp "$COMPLETION_OUT_DIR/apply-user-defaults.bash" "$PACKAGE_NAME/complete/" 30 | cp "$COMPLETION_OUT_DIR/apply-user-defaults.fish" "$PACKAGE_NAME/complete/" 31 | 32 | strip "$PACKAGE_NAME/apply-user-defaults" 33 | 34 | tar czvf "$PACKAGE_NAME.tar.gz" "$PACKAGE_NAME" 35 | -------------------------------------------------------------------------------- /src/cli.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Michael Sanders 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT License , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | 8 | use clap::{App, Arg, crate_version, crate_authors}; 9 | 10 | pub fn build_cli() -> App<'static, 'static> { 11 | App::new("apply-user-defaults") 12 | .version(crate_version!()) 13 | .author(crate_authors!()) 14 | .about("Apply macOS user defaults in bulk from YAML file.") 15 | .arg( 16 | Arg::with_name("dry-run") 17 | .short("d") 18 | .long("dry-run") 19 | .help("Don’t actually run anything, just show what would be done."), 20 | ) 21 | .arg( 22 | Arg::with_name("no-env") 23 | .long("no-env") 24 | .help("Disable environment variable expansion"), 25 | ) 26 | .arg( 27 | Arg::with_name("quiet") 28 | .short("q") 29 | .long("quiet") 30 | .help("Quiet mode: suppress normal output"), 31 | ) 32 | .arg( 33 | Arg::with_name("verbose") 34 | .short("v") 35 | .long("verbose") 36 | .help("Verbose mode: include diagnostic info in output"), 37 | ) 38 | .arg( 39 | Arg::with_name("FILE") 40 | .help("Sets the input file to use") 41 | .required(true), 42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Michael Sanders 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT License , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | 8 | use clap::ArgMatches; 9 | use colored::*; 10 | use regex::Regex; 11 | use std::error::Error; 12 | use std::io::Write; 13 | use std::process::Command; 14 | use std::{env, fs, io, process}; 15 | use yaml_rust::yaml::{Yaml, YamlLoader}; 16 | 17 | #[macro_use] 18 | mod messages; 19 | mod cli; 20 | 21 | #[macro_use] 22 | extern crate lazy_static; 23 | 24 | type Result = ::std::result::Result>; 25 | 26 | fn main() { 27 | try_main(cli::build_cli().get_matches()).unwrap_or_else(|err| { 28 | eprintln!("{}: {}", "Error".red(), err); 29 | process::exit(1) 30 | }); 31 | } 32 | 33 | fn try_main(args: ArgMatches) -> Result<()> { 34 | let filename = args.value_of("FILE").unwrap(); 35 | let body = 36 | fs::read_to_string(filename).map_err(|err| format!("Could not open file. {}", err))?; 37 | let expand_env_enabled = !args.is_present("no-env"); 38 | 39 | messages::set_quiet_output(args.is_present("quiet")); 40 | messages::set_dry_run_output(args.is_present("dry-run")); 41 | messages::set_verbose_output(args.is_present("verbose")); 42 | 43 | let docs = YamlLoader::load_from_str(&body)?; 44 | let doc = &docs[0]; 45 | let defaults = doc 46 | .as_hash() 47 | .ok_or_else(|| format!("Unexpected document type. Expected hash, got {:?}", doc))?; 48 | for (domain, values) in defaults { 49 | let domain = domain 50 | .as_str() 51 | .ok_or_else(|| format!("Unexpected domain value. Expected string, got {:?}", domain))?; 52 | let values = values 53 | .as_hash() 54 | .ok_or_else(|| format!("Unexpected value. Expected hash, got {:?}", values))?; 55 | for (key, value) in values { 56 | let key = key 57 | .as_str() 58 | .ok_or_else(|| format!("Unexpected value. Expected string, got {:?}", key))?; 59 | write_default(domain, key, value, expand_env_enabled)?; 60 | } 61 | } 62 | 63 | if !messages::dry_run_output() { 64 | message!("Applied defaults."); 65 | } 66 | Ok(()) 67 | } 68 | 69 | /// Writes the given value as the value for key in domain using the `defaults 70 | /// write` command. Value types are automatically inferred from the YAML enum. 71 | /// 72 | /// If `expand_env_enabled` is true, environment variables in template string 73 | /// syntax are expanded. 74 | fn write_default(domain: &str, key: &str, value: &Yaml, expand_env_enabled: bool) -> Result<()> { 75 | let (value_type, value): (&str, std::string::String) = match value { 76 | Yaml::Real(x) => ("-float", x.to_string()), 77 | Yaml::Integer(x) => ("-int", x.to_string()), 78 | Yaml::Boolean(x) => ("-bool", x.to_string()), 79 | Yaml::String(x) => ("-string", x.to_string()), 80 | _ => ("", "".to_string()), 81 | }; 82 | 83 | let value = if expand_env_enabled { 84 | expand_env_template(value.as_str()) 85 | } else { 86 | value 87 | }; 88 | 89 | command_message!("defaults write {} {} {} {}", domain, key, value_type, value); 90 | if messages::dry_run_output() { 91 | Ok(()) 92 | } else { 93 | let output = Command::new("/usr/bin/defaults") 94 | .arg("write") 95 | .arg(domain) 96 | .arg(key) 97 | .arg(value_type) 98 | .arg(value) 99 | .output() 100 | .map_err(|err| format!("Failed to invoke defaults command. {}", err))?; 101 | 102 | io::stdout().write_all(&output.stdout)?; 103 | io::stderr().write_all(&output.stderr)?; 104 | 105 | if output.status.success() { 106 | Ok(()) 107 | } else { 108 | match output.status.code() { 109 | Some(code) => process::exit(code), 110 | None => Err("Process terminated by signal".into()), 111 | } 112 | } 113 | } 114 | } 115 | 116 | /// Expands any template strings in the given string in the form of `${VAR}` 117 | /// with matching environment variables. 118 | fn expand_env_template(body: &str) -> std::string::String { 119 | lazy_static! { 120 | static ref RE: Regex = Regex::new(r"([^\\]|^)(\$\{(\w+)\})").unwrap(); 121 | static ref RE_ESCAPED: Regex = Regex::new(r"(\\(\$\{(\w+)\}))").unwrap(); 122 | } 123 | 124 | let mut output: std::string::String = body.into(); 125 | for cap in RE.captures_iter(body) { 126 | let outer = &cap.get(2).unwrap(); 127 | let inner = &cap.get(3).unwrap(); 128 | if let Ok(replacement) = env::var(inner.as_str()) { 129 | output.replace_range(outer.start()..outer.end(), replacement.as_str()); 130 | } 131 | } 132 | RE_ESCAPED.replace_all(output.as_str(), "$2").into() 133 | } 134 | -------------------------------------------------------------------------------- /src/messages.rs: -------------------------------------------------------------------------------- 1 | // Adopted from 2 | // https://github.com/BurntSushi/ripgrep/blob/8892bf/src/messages.rs under the 3 | // MIT License. 4 | // 5 | // Copyright (c) 2015 Andrew Gallant 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | // SOFTWARE. 24 | // 25 | // This file has been sublicensed by Michael Sanders under the Apache License, 26 | // Version 2.0, or 27 | // the MIT License (see above, and ), at your option. This file may not be 29 | // copied, modified, or distributed except according to those terms. 30 | 31 | use std::sync::atomic::{AtomicBool, Ordering}; 32 | 33 | static QUIET_OUTPUT: AtomicBool = AtomicBool::new(false); 34 | static DRY_RUN_OUTPUT: AtomicBool = AtomicBool::new(false); 35 | static VERBOSE_OUTPUT: AtomicBool = AtomicBool::new(false); 36 | 37 | /// Emit a successful message to stdout, unless quiet output is enabled. 38 | #[macro_export] 39 | macro_rules! message { 40 | ($($tt:tt)*) => { 41 | if !$crate::messages::quiet_output() { 42 | println!("{} {}", "Success!".underline().green(), format!($($tt)*)) 43 | } 44 | } 45 | } 46 | 47 | /// Emit a non-fatal diagnostic message to stdout, if verbose output is enabled 48 | /// and quiet output is disabled. 49 | #[macro_export] 50 | macro_rules! verbose_message { 51 | ($($tt:tt)*) => { 52 | if !$crate::messages::quiet_output() && $crate::messages::verbose_output() { 53 | println!("{} {}", "==>".bold().blue(), format!($($tt)*)); 54 | } 55 | } 56 | } 57 | 58 | /// Emit a non-fatal diagnostic message to stdout, if dry run or verbose output 59 | /// is enabled and quiet output is disabled. 60 | #[macro_export] 61 | macro_rules! command_message { 62 | ($($tt:tt)*) => { 63 | if !$crate::messages::dry_run_output() { 64 | // Distinguish between verbose and dry-run modes. 65 | verbose_message!($($tt)*) 66 | } else if !$crate::messages::quiet_output() { 67 | println!("{} {}", "==>".bold().yellow(), format!($($tt)*)); 68 | } 69 | } 70 | } 71 | 72 | /// Returns true if and only if messages should not be shown. 73 | pub fn quiet_output() -> bool { 74 | QUIET_OUTPUT.load(Ordering::SeqCst) 75 | } 76 | 77 | /// Set whether messages should be shown or not. 78 | /// 79 | /// By default, they are shown. 80 | pub fn set_quiet_output(yes: bool) { 81 | QUIET_OUTPUT.store(yes, Ordering::SeqCst) 82 | } 83 | 84 | /// Returns true if and only if dry_run messages should be shown. 85 | pub fn dry_run_output() -> bool { 86 | DRY_RUN_OUTPUT.load(Ordering::SeqCst) 87 | } 88 | 89 | /// Set whether "dry_run" related messages should be shown or not. 90 | /// 91 | /// By default, they are not shown. 92 | /// 93 | /// Note that this is overridden if `quiet_output` is enabled. Namely, if 94 | /// `quiet_output` is enabled, then "dry_run" messages are never shown, 95 | /// regardless of this setting. 96 | pub fn set_dry_run_output(yes: bool) { 97 | DRY_RUN_OUTPUT.store(yes, Ordering::SeqCst) 98 | } 99 | 100 | /// Returns true if and only if verbose messages should be shown. 101 | pub fn verbose_output() -> bool { 102 | VERBOSE_OUTPUT.load(Ordering::SeqCst) 103 | } 104 | 105 | /// Set whether "verbose" related messages should be shown or not. 106 | /// 107 | /// By default, they are not shown. 108 | /// 109 | /// Note that this is overridden if `quiet_output` is enabled. Namely, if 110 | /// `quiet_output` is enabled, then "verbose" messages are never shown, 111 | /// regardless of this setting. 112 | pub fn set_verbose_output(yes: bool) { 113 | VERBOSE_OUTPUT.store(yes, Ordering::SeqCst) 114 | } 115 | -------------------------------------------------------------------------------- /tests/assets/defaults-escaped.yml: -------------------------------------------------------------------------------- 1 | com.apple.desktopservices: 2 | # Disable .DS_Store files on network drives. 3 | DSDontWriteNetworkStores: true 4 | 5 | com.apple.dock: 6 | # System Preferences > Dock > Automatically hide and show the Dock. 7 | autohide: true 8 | 9 | com.apple.finder: 10 | # Finder > Preferences > New Finder windows show > Home directory. 11 | NewWindowTarget: PfHm 12 | 13 | # Finder > Preferences > New Finder windows show > Home directory. 14 | NewWindowTargetPath: 'file://\${HOME}' 15 | -------------------------------------------------------------------------------- /tests/assets/defaults.yml: -------------------------------------------------------------------------------- 1 | com.apple.desktopservices: 2 | # Disable .DS_Store files on network drives. 3 | DSDontWriteNetworkStores: true 4 | 5 | com.apple.dock: 6 | # System Preferences > Dock > Automatically hide and show the Dock. 7 | autohide: true 8 | 9 | com.apple.finder: 10 | # Finder > Preferences > New Finder windows show > Home directory. 11 | NewWindowTarget: PfHm 12 | 13 | # Finder > Preferences > New Finder windows show > Home directory. 14 | NewWindowTargetPath: 'file://${HOME}' 15 | -------------------------------------------------------------------------------- /tests/integration.rs: -------------------------------------------------------------------------------- 1 | extern crate assert_cli; 2 | use std::env; 3 | use std::path; 4 | 5 | #[test] 6 | fn dry_run() { 7 | let defaults_path = asset_path().join("defaults.yml"); 8 | let expected_output = format!( 9 | "==> defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true 10 | ==> defaults write com.apple.dock autohide -bool true 11 | ==> defaults write com.apple.finder NewWindowTarget -string PfHm 12 | ==> defaults write com.apple.finder NewWindowTargetPath -string file://{}", 13 | env::var("HOME").unwrap() 14 | ); 15 | assert_cli::Assert::main_binary() 16 | .with_args(&[defaults_path.to_str().unwrap(), "--dry-run"]) 17 | .stdout() 18 | .is(expected_output.as_str()) 19 | .unwrap(); 20 | } 21 | 22 | #[test] 23 | fn dry_run_no_env() { 24 | let defaults_path = asset_path().join("defaults.yml"); 25 | let expected_output = 26 | "==> defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true 27 | ==> defaults write com.apple.dock autohide -bool true 28 | ==> defaults write com.apple.finder NewWindowTarget -string PfHm 29 | ==> defaults write com.apple.finder NewWindowTargetPath -string file://${HOME}"; 30 | assert_cli::Assert::main_binary() 31 | .with_args(&[defaults_path.to_str().unwrap(), "--dry-run", "--no-env"]) 32 | .stdout() 33 | .is(expected_output) 34 | .unwrap(); 35 | } 36 | 37 | #[test] 38 | fn dry_run_escaped_env() { 39 | let defaults_path = asset_path().join("defaults-escaped.yml"); 40 | let expected_output = 41 | "==> defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true 42 | ==> defaults write com.apple.dock autohide -bool true 43 | ==> defaults write com.apple.finder NewWindowTarget -string PfHm 44 | ==> defaults write com.apple.finder NewWindowTargetPath -string file://${HOME}"; 45 | assert_cli::Assert::main_binary() 46 | .with_args(&[defaults_path.to_str().unwrap(), "--dry-run"]) 47 | .stdout() 48 | .is(expected_output) 49 | .unwrap(); 50 | } 51 | 52 | #[inline] 53 | fn asset_path() -> path::PathBuf { 54 | path::Path::new(file!()).parent().unwrap().join("assets") 55 | } 56 | --------------------------------------------------------------------------------