Expand description
Put an app’s bundled command-line tool on the user’s PATH, the way editors offer an
“Install command” menu item.
The tool ships inside the app (on macOS <App>.app/Contents/Helpers/<name>). Installing makes
a symbolic link <bin dir>/<name> → that file, so updating the app updates the tool:
- The link goes in
/usr/local/bin(created when missing). - When that folder isn’t writable, the OS asks for an administrator password (macOS: the
standard
do shell script … with administrator privilegesprompt). - When that is declined (or no prompt is available), the link goes in
~/.local/binand the result carries the line to add to the shell profile.
A file or link that isn’t this app’s tool is never replaced unless the caller passes
replace (and the result names what was replaced). A link left behind after the app moved
(it points at a missing …/Contents/Helpers/<name>) is repaired without asking. A folder is
never replaced.
ENV_BIN_DIR and ENV_FALLBACK_DIR point both folders elsewhere for tests; while
either is set the administrator prompt is never shown.
commands are the matching command specs (app.installCommandLineTool,
app.uninstallCommandLineTool, app.commandLineToolStatus) for any host that implements
CliToolHost; run runs the same three for apps with their own command router.
Structs§
- CliTool
- One app’s bundled command-line tool and where to install it.
- Installed
- What
CliTool::installdid. - Removed
- What
CliTool::uninstalldid. - Status
- Where the tool is installed, if anywhere.
Enums§
- CliTool
Error - Why installing or removing the tool did not happen.
- Elevated
- The answer to an administrator prompt.
- Elevation
- How to get administrator rights when the system folder isn’t writable.
- Link
State - What one location holds.
Constants§
- ENV_
BIN_ DIR - Install into this folder instead of
SYSTEM_BIN_DIR(tests); disables the admin prompt. - ENV_
FALLBACK_ DIR - Fall back to this folder instead of
~/.local/bin(tests); disables the admin prompt. - INSTALL
- Command ids registered by
commands. - STATUS
- SYSTEM_
BIN_ DIR - Where the link goes by default: on every macOS
PATH(/etc/paths). - UNINSTALL
Traits§
- CliTool
Host - A command host that can hand out its app’s
CliTool(Nonein a development build with no bundled tool: the commands are then disabled with a reason).
Functions§
- bundled_
helper - The bundled tool’s path for the running app:
<exe dir>/../Helpers/<name>, which on macOS is<App>.app/Contents/Helpers/<name>. - check_
name - A tool name: lowercase ASCII letters, digits,
-,_,.; not starting with-or.. - commands
app.installCommandLineToolandapp.uninstallCommandLineToolinmenu(macOS: the app menu,&["<App name>"]), and the menu-less queryapp.commandLineToolStatus. Each returns the outcome as JSON with amessagefor a toast.- run
- Run
INSTALL(paramreplace),UNINSTALLorSTATUSontool, for apps that route commands themselves instead of through aashlar_command::Registry. The result is the outcome as JSON with amessagefor a toast;Nonewhenidis none of the three. - sh_
quote pas one single-quoted/bin/shword. Refuses non-UTF-8 and control characters.
Type Aliases§
- Elevator
- Runs a
/bin/shscript with administrator rights. The script is built by this module from fixed commands and single-quoted paths.