Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ arguments it checks your outdated Homebrew casks:

```sh
$BIN preview
$BIN preview --all-apps --only-noteworthy --min-tier warn
$BIN preview --all-apps --only-noteworthy --min-tier high
$BIN preview --json
$BIN preview --fetch firefox # download the incoming build and diff it
```

`preview` is inform-only: it never runs `brew`, never blocks an update, and
always exits 0. It understands `.dmg` and `.zip` cask artifacts; `.pkg` is
`preview` is inform-only: it runs read-only `brew` queries but never
`brew upgrade`, never blocks an update, and exits 0 whenever it completes (2
on a usage error or when Homebrew is missing). It understands `.dmg` and `.zip` cask artifacts; `.pkg` is
skipped. With `--fetch`, an incoming build is analysed *before* Gatekeeper has
cleared it, so a one-off notarization difference can simply be a fresh-download
artifact — the output flags this when it happens.
Expand All @@ -102,6 +103,13 @@ Running `privacycommand` with no arguments opens an interactive browser when
stdin and stdout are a terminal, and prints usage otherwise so CI callers do
not hang.

`privacycommand completion <zsh|bash|fish>` prints a tab-completion script.
The scripts are generated from the command tables in
`Sources/privacycommandCLIKit/ShellCompletion.swift`, so a new subcommand or
flag goes there as well as into the command's help text; `ShellCompletionTests`
checks every table entry reaches every shell and that the scripts parse. The
app build writes them into the bundle for the Homebrew cask to link.

## What CI runs

Two workflows run on every pull request against `main`:
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ brew install --cask privacykey/tap/privacycommand

**Command line** — the app also carries a command-line tool of the same name, `privacycommand`, which runs the same analyser from Terminal. There are two ways to put it on your `PATH`:

- **Homebrew** — the cask links `privacycommand` for you on install and removes it on uninstall. Nothing else to do.
- **Homebrew** — the cask links `privacycommand` for you on install, along with its zsh, bash and fish tab completion, and removes them on uninstall. Nothing else to do.
- **Direct download** — choose **privacycommand ▸ Install Command Line Tool…**. It links the copy inside the app into `/usr/local/bin`, so the tool updates with the app. When that folder needs administrator rights, as it does on most Macs, it shows the `sudo ln -s` command to paste into Terminal instead, with a button that copies it. The same menu item then reads **Uninstall Command Line Tool…** and removes the link.

```sh
Expand All @@ -70,7 +70,13 @@ privacycommand preview # check outdated Homebrew casks before you upgrad
privacycommand --help # every command and flag
```

`preview` inspects Homebrew casks *before* you update them; it never runs `brew`, never blocks an update, and always exits 0. To build the CLI from source instead, see [CONTRIBUTING.md](CONTRIBUTING.md#the-privacycommand-cli).
**Tab completion** — Homebrew sets it up. Otherwise add one line to your shell's startup file; `privacycommand completion --help` lists them. For zsh, put this in `~/.zshrc` after `compinit`:

```sh
eval "$(privacycommand completion zsh)"
```

`preview` inspects Homebrew casks *before* you update them. It runs read-only `brew` queries but never `brew upgrade`, never blocks an update, and exits 0 whenever it completes. To build the CLI from source instead, see [CONTRIBUTING.md](CONTRIBUTING.md#the-privacycommand-cli).

## Docs

Expand Down
5 changes: 5 additions & 0 deletions packaging/homebrew/privacycommand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
# and removes the link on uninstall. DMG installs use the app menu's
# Install Command Line Tool… item instead.
binary "#{appdir}/privacycommand.app/Contents/Helpers/privacycommand"
# Its tab completion, generated at build time by `privacycommand
# completion <shell>`.
bash_completion "#{appdir}/privacycommand.app/Contents/Resources/completions/privacycommand.bash"
zsh_completion "#{appdir}/privacycommand.app/Contents/Resources/completions/_privacycommand"
fish_completion "#{appdir}/privacycommand.app/Contents/Resources/completions/privacycommand.fish"

# We're not sandboxed, so quitting the app is enough — no need for
# a tighter `quit:` predicate. The in-app Sparkle updater is
Expand Down
7 changes: 5 additions & 2 deletions privacycommand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ fiddling that earlier versions of this README walked through. The
builds the `privacycommand` CLI with SwiftPM for the app's architectures,
stamps the app's version into it, copies it to
`Contents/Helpers/privacycommand` and signs it with the app's identity and
hardened runtime. The Homebrew cask's `binary` stanza and the app
menu's Install Command Line Tool… item both link to that path.
hardened runtime. It also runs `privacycommand completion <shell>` to
write zsh, bash and fish completion scripts to
`Contents/Resources/completions`. The Homebrew cask's `binary` and
`*_completion` stanzas link those, and the app menu's Install Command
Line Tool… item links the binary.
- Sparkle 2 wired in for in-app updates (you have to add it once via
**File → Add Package Dependencies…** — see the top-level README).

Expand Down
1 change: 1 addition & 0 deletions privacycommand/Resources/Manual/07-reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ privacycommand also comes with a command-line tool of the same name, `privacycom

- **Installed with Homebrew:** the cask has already put the `privacycommand` command on your `PATH`.
- **Installed from the disk image:** choose **privacycommand ▸ Install Command Line Tool…**. It links the copy inside the app into `/usr/local/bin`, so the tool updates with the app. If that folder needs administrator rights, the alert shows the `sudo` command to run in Terminal instead, with a button that copies it. Choose **Uninstall Command Line Tool…** from the same place to remove the link.
- **Tab completion:** Homebrew installs it for zsh, bash and fish. Otherwise run `privacycommand completion --help` for the line to add to your shell's startup file, for example `eval "$(privacycommand completion zsh)"` in `~/.zshrc`.

Run privacycommand from the Applications folder before installing the tool: a link into a copy that is still on the disk image stops working when the image is ejected, so the item asks you to move the app first.
30 changes: 28 additions & 2 deletions privacycommand/Scripts/embed-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# privacycommand.app/Contents/Helpers/privacycommand, and sign it with the
# app's identity and hardened runtime so the notarized bundle stays valid.
#
# Also writes its zsh, bash and fish completion scripts to
# Contents/Resources/completions.
#
# Runs as the app target's "Embed command-line tool" build phase. Homebrew's
# cask links the embedded binary onto PATH (the `binary` stanza in
# packaging/homebrew/privacycommand.rb); DMG installs link it from the app
# menu's Install Command Line Tool… item.
# packaging/homebrew/privacycommand.rb) and the completions into its
# completion folders; DMG installs link the binary from the app menu's
# Install Command Line Tool… item.

set -euo pipefail

Expand Down Expand Up @@ -78,6 +82,28 @@ chmod 755 "${DEST}/${PRODUCT}"
# slice, so unsigned builds still run.
xcrun strip -S -x "${DEST}/${PRODUCT}"

# Tab completion for the cask's *_completion stanzas, generated by the CLI
# itself so the scripts always match its options. This runs the SwiftPM build
# rather than the copy just embedded: macOS silently drops what a binary
# writes into its own freshly built .app on its first run, which left
# _privacycommand empty.
GENERATED="${DERIVED_FILE_DIR}/completions"
COMPLETIONS="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/completions"
mkdir -p "${GENERATED}" "${COMPLETIONS}"
for SHELL_NAME in zsh bash fish; do
case "${SHELL_NAME}" in
zsh) FILE=_privacycommand ;;
bash) FILE=privacycommand.bash ;;
fish) FILE=privacycommand.fish ;;
esac
"${BIN}" completion "${SHELL_NAME}" > "${GENERATED}/${FILE}"
if [[ ! -s "${GENERATED}/${FILE}" ]]; then
echo "error: \`${PRODUCT} completion ${SHELL_NAME}\` printed nothing" >&2
exit 1
fi
cp -f "${GENERATED}/${FILE}" "${COMPLETIONS}/${FILE}"
done

# Follow Xcode's signing choice for unsigned builds (App CI).
if [[ "${CODE_SIGNING_ALLOWED:-YES}" == "NO" ]]; then
echo "Embedded ${PRODUCT} without signing (CODE_SIGNING_ALLOWED=NO)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ final class CommandLineToolInstaller: ObservableObject {
refresh()
inform("The command-line tool is installed",
"\(tool.link.path) now links to the copy inside privacycommand, so it updates with the app. "
+ "Open a new Terminal window and run “privacycommand --help” to get started.")
+ "Open a new Terminal window and run “privacycommand --help” to get started. "
+ "For tab completion, see “privacycommand completion --help”.")
} catch {
refresh()
report(error, verb: "install")
Expand Down
40 changes: 40 additions & 0 deletions privacycommand/Sources/privacycommandCLI/CompletionCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Foundation
import privacycommandCLIKit

/// `privacycommand completion <shell>` — print a tab-completion script.
/// The scripts themselves are generated by `ShellCompletion`.
enum CompletionCommand {

static let help = """
usage: privacycommand completion <zsh|bash|fish>

Print a tab-completion script for your shell. A Homebrew install sets these
up for you. Otherwise, add one of these:

zsh in ~/.zshrc, after `autoload -Uz compinit && compinit`:
eval "$(privacycommand completion zsh)"
bash in ~/.bash_profile:
eval "$(privacycommand completion bash)"
fish run once:
privacycommand completion fish > ~/.config/fish/completions/privacycommand.fish

Completes subcommands, options, installed app names, risk tiers, and the
outdated casks `preview` would look at.
"""

static func run(_ argv: [String]) -> Never {
guard let first = argv.first else { die("no shell given.\n\n" + help, code: 2) }
if first == "-h" || first == "--help" {
print(help)
exit(0)
}
guard argv.count == 1 else {
die("completion takes one shell (extra argument: \(argv[1]))", code: 2)
}
guard let shell = ShellCompletion.Shell(rawValue: first) else {
die("unknown shell: \(first) (one of: zsh, bash, fish)", code: 2)
}
print(ShellCompletion.script(for: shell), terminator: "")
exit(0)
}
}
7 changes: 6 additions & 1 deletion privacycommand/Sources/privacycommandCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import privacycommandCLIKit
// privacycommand audit <target> same, explicit
// privacycommand -i | interactive force the interactive browser
// privacycommand preview [options] preview the apps you're about to update
// privacycommand completion <shell> print a zsh, bash or fish completion script
//
// `<target>` is a path to a .app or an app-name substring matched against
// installed apps. See `AuditCommand` / `privacycommand audit --help`.
Expand All @@ -34,9 +35,11 @@ usage:
privacycommand audit <target> same, explicit
privacycommand -i, interactive force the interactive browser
privacycommand preview [options] preview apps before you update them
privacycommand completion <shell> print a tab-completion script (zsh, bash, fish)

<target> is a path to a .app or an app-name substring (like `witr`).
Run `privacycommand audit --help` or `privacycommand preview --help` for options.
Run `privacycommand audit --help`, `privacycommand preview --help` or
`privacycommand completion --help` for details.
"""

private func stdioIsTTY() -> Bool {
Expand All @@ -55,6 +58,8 @@ case "preview":
PreviewCommand.run(Array(arguments.dropFirst()))
case "audit":
AuditCommand.run(Array(arguments.dropFirst()))
case "completion":
CompletionCommand.run(Array(arguments.dropFirst()))
case "-i", "--interactive", "interactive":
InteractiveCommand.run()
case "--tui-selftest":
Expand Down
Loading
Loading