Skip to content

Commit 938e9b2

Browse files
authored
app support in Pkg (#3772)
This provides initial support for defining "apps" in Julia which can be run from the terminal and installed via Pkg.
1 parent df1931a commit 938e9b2

File tree

16 files changed

+677
-14
lines changed

16 files changed

+677
-14
lines changed

docs/src/apps.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# [**?.** Apps](@id Apps)
2+
3+
!!! note
4+
The app support in Pkg is currently considered experimental and some functionality and API may change.
5+
6+
Some inconveniences that can be encountered are:
7+
- You need to manually make `~/.julia/bin` available on the PATH environment.
8+
- The path to the julia executable used is the same as the one used to install the app. If this
9+
julia installation gets removed, you might need to reinstall the app.
10+
- You can only have one app installed per package.
11+
12+
Apps are Julia packages that are intended to be run as a "standalone programs" (by e.g. typing the name of the app in the terminal possibly together with some arguments or flags/options).
13+
This is in contrast to most Julia packages that are used as "libraries" and are loaded by other files or in the Julia REPL.
14+
15+
## Creating a Julia app
16+
17+
A Julia app is structured similar to a standard Julia library with the following additions:
18+
19+
- A `@main` entry point in the package module (see the [Julia help on `@main`](https://docs.julialang.org/en/v1/manual/command-line-interface/#The-Main.main-entry-point) for details)
20+
- An `[app]` section in the `Project.toml` file listing the executable names that the package provides.
21+
22+
A very simple example of an app that prints the reversed input arguments would be:
23+
24+
```julia
25+
# src/MyReverseApp.jl
26+
module MyReverseApp
27+
28+
function (@main)(ARGS)
29+
for arg in ARGS
30+
print(stdout, reverse(arg), " ")
31+
end
32+
return
33+
end
34+
35+
end # module
36+
```
37+
38+
```toml
39+
# Project.toml
40+
41+
# standard fields here
42+
43+
[apps]
44+
reverse = {}
45+
```
46+
The empty table `{}` is to allow for giving metadata about the app but it is currently unused.
47+
48+
After installing this app one could run:
49+
50+
```
51+
$ reverse some input string
52+
emos tupni gnirts
53+
```
54+
55+
directly in the terminal.
56+
57+
## Installing Julia apps
58+
59+
The installation of Julia apps are similar to installing julia libraries but instead of using e.g. `Pkg.add` or `pkg> add` one uses `Pkg.Apps.add` or `pkg> app add` (`develop` is also available).

ext/REPLExt/completions.jl

+17
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ function complete_add_dev(options, partial, i1, i2; hint::Bool)
156156
return comps, idx, !isempty(comps)
157157
end
158158

159+
# TODO: Move
160+
import Pkg: Operations, Types, Apps
161+
function complete_installed_apps(options, partial; hint)
162+
manifest = try
163+
Types.read_manifest(joinpath(Apps.app_env_folder(), "AppManifest.toml"))
164+
catch err
165+
err isa PkgError || rethrow()
166+
return String[]
167+
end
168+
apps = String[]
169+
for (uuid, entry) in manifest.deps
170+
append!(apps, keys(entry.apps))
171+
push!(apps, entry.name)
172+
end
173+
return unique!(apps)
174+
end
175+
159176
########################
160177
# COMPLETION INTERFACE #
161178
########################

0 commit comments

Comments
 (0)