scalar: implement 'scalar list'
The produced list simply consists of those repositories registered under the multi-valued `scalar.repo` config setting in the user's Git config. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Dec 3, 2021 at 13:34 UTC
2b7104573ce237398131562c465d838c018d5880
2 files changed
+21
-1
contrib/scalar/scalar.c
+11
@@ -251,6 +251,16 @@ static int unregister_dir(void)
251
return res;
252
}
253
254
+static int cmd_list(int argc, const char **argv)
255
+{
256
+ if (argc != 1)
257
+ die(_("`scalar list` does not take arguments"));
258
+
259
+ if (run_git("config", "--global", "--get-all", "scalar.repo", NULL) < 0)
260
+ return -1;
261
+ return 0;
262
+}
263
+
264
static int cmd_register(int argc, const char **argv)
265
{
266
struct option options[] = {
@@ -337,6 +347,7 @@ static struct {
347
const char *name;
348
int (*fn)(int, const char **);
349
} builtins[] = {
350
+ { "list", cmd_list },
351
{ "register", cmd_register },
352
{ "unregister", cmd_unregister },
353
{ NULL, NULL},
contrib/scalar/scalar.txt
+10
-1
@@ -8,6 +8,7 @@ scalar - an opinionated repository management tool
8
SYNOPSIS
9
--------
10
[verse]
11
+scalar list
12
scalar register [<enlistment>]
13
scalar unregister [<enlistment>]
14
@@ -28,11 +29,19 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment
29
will be identical to the worktree.
30
31
The `scalar` command implements various subcommands, and different options
31
-depending on the subcommand.
32
+depending on the subcommand. With the exception of `list`, all subcommands
33
+expect to be run in an enlistment.
34
35
COMMANDS
36
--------
37
38
+List
39
+~~~~
40
+
41
+list::
42
+ List enlistments that are currently registered by Scalar. This
43
+ subcommand does not need to be run inside an enlistment.
44
+
45
Register
46
~~~~~~~~
47