From 05e38eb8ac23246ab7ae2eafc2445ed87b72b830 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Wed, 13 Nov 2024 00:59:22 +0100 Subject: [PATCH 1/2] update documentation --- cmd/plakar/subcommands.go | 1 + cmd/plakar/subcommands/man/docs/archive.md | 2 +- cmd/plakar/subcommands/man/docs/backup.md | 2 +- cmd/plakar/subcommands/man/docs/cat.md | 2 +- cmd/plakar/subcommands/man/docs/checksum.md | 2 +- cmd/plakar/subcommands/man/docs/cleanup.md | 2 +- cmd/plakar/subcommands/man/docs/clone.md | 2 +- cmd/plakar/subcommands/man/docs/create.md | 2 +- cmd/plakar/subcommands/man/docs/diff.md | 2 +- cmd/plakar/subcommands/man/docs/exec.md | 2 +- cmd/plakar/subcommands/man/docs/find.md | 2 +- cmd/plakar/subcommands/man/docs/info.md | 2 +- cmd/plakar/subcommands/man/docs/ls.md | 2 +- cmd/plakar/subcommands/man/docs/mount.md | 2 +- cmd/plakar/subcommands/man/docs/restore.md | 2 +- cmd/plakar/subcommands/man/docs/rm.md | 2 +- cmd/plakar/subcommands/man/docs/server.md | 2 +- cmd/plakar/subcommands/man/docs/stdio.md | 2 +- cmd/plakar/subcommands/man/docs/sync.md | 2 +- cmd/plakar/subcommands/man/docs/ui.md | 2 +- cmd/plakar/subcommands/man/docs/verify.md | 2 +- cmd/plakar/subcommands/man/docs/version.md | 2 +- cmd/plakar/subcommands/tags/tags.1 | 75 ++++++++++++++++++ cmd/plakar/subcommands/tags/tags.go | 88 +++++++++++++++++++++ 24 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 cmd/plakar/subcommands/tags/tags.1 create mode 100644 cmd/plakar/subcommands/tags/tags.go diff --git a/cmd/plakar/subcommands.go b/cmd/plakar/subcommands.go index f5af29a1..6f57683f 100644 --- a/cmd/plakar/subcommands.go +++ b/cmd/plakar/subcommands.go @@ -20,6 +20,7 @@ import ( _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/server" _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/stdio" _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/sync" + _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/tags" _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/ui" _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/verify" _ "github.com/PlakarKorp/plakar/cmd/plakar/subcommands/version" diff --git a/cmd/plakar/subcommands/man/docs/archive.md b/cmd/plakar/subcommands/man/docs/archive.md index 15f44765..95744aea 100644 --- a/cmd/plakar/subcommands/man/docs/archive.md +++ b/cmd/plakar/subcommands/man/docs/archive.md @@ -92,4 +92,4 @@ The **plakar archive** utility exits 0 on success, and >0 if an err plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/backup.md b/cmd/plakar/subcommands/man/docs/backup.md index 8d1d563c..c7f88958 100644 --- a/cmd/plakar/subcommands/man/docs/backup.md +++ b/cmd/plakar/subcommands/man/docs/backup.md @@ -86,4 +86,4 @@ The **plakar backup** utility exits 0 on success, and >0 if an erro plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/cat.md b/cmd/plakar/subcommands/man/docs/cat.md index b991509d..45183c24 100644 --- a/cmd/plakar/subcommands/man/docs/cat.md +++ b/cmd/plakar/subcommands/man/docs/cat.md @@ -70,4 +70,4 @@ The **plakar cat** utility exits 0 on success, and >0 if an error o plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/checksum.md b/cmd/plakar/subcommands/man/docs/checksum.md index bd63157d..0c4803fc 100644 --- a/cmd/plakar/subcommands/man/docs/checksum.md +++ b/cmd/plakar/subcommands/man/docs/checksum.md @@ -66,4 +66,4 @@ The **plakar checksum** utility exits 0 on success, and >0 if an er plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/cleanup.md b/cmd/plakar/subcommands/man/docs/cleanup.md index e8e3384e..745a0e37 100644 --- a/cmd/plakar/subcommands/man/docs/cleanup.md +++ b/cmd/plakar/subcommands/man/docs/cleanup.md @@ -49,4 +49,4 @@ The **plakar cleanup** utility exits 0 on success, and >0 if an err plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/clone.md b/cmd/plakar/subcommands/man/docs/clone.md index e255650e..1786bd05 100644 --- a/cmd/plakar/subcommands/man/docs/clone.md +++ b/cmd/plakar/subcommands/man/docs/clone.md @@ -44,4 +44,4 @@ The **plakar clone** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/create.md b/cmd/plakar/subcommands/man/docs/create.md index 98f86a3b..f44aba1b 100644 --- a/cmd/plakar/subcommands/man/docs/create.md +++ b/cmd/plakar/subcommands/man/docs/create.md @@ -85,4 +85,4 @@ The **plakar create** utility exits 0 on success, and >0 if an erro plakar(1), plakar-repository(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/diff.md b/cmd/plakar/subcommands/man/docs/diff.md index 176cf7f4..b3de1ede 100644 --- a/cmd/plakar/subcommands/man/docs/diff.md +++ b/cmd/plakar/subcommands/man/docs/diff.md @@ -63,4 +63,4 @@ The **plakar diff** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/exec.md b/cmd/plakar/subcommands/man/docs/exec.md index bb94e28a..719c97b1 100644 --- a/cmd/plakar/subcommands/man/docs/exec.md +++ b/cmd/plakar/subcommands/man/docs/exec.md @@ -59,4 +59,4 @@ The **plakar exec** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/find.md b/cmd/plakar/subcommands/man/docs/find.md index 0c655dc9..2fbed983 100644 --- a/cmd/plakar/subcommands/man/docs/find.md +++ b/cmd/plakar/subcommands/man/docs/find.md @@ -51,4 +51,4 @@ The **plakar find** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/info.md b/cmd/plakar/subcommands/man/docs/info.md index fd5332eb..82cc161d 100644 --- a/cmd/plakar/subcommands/man/docs/info.md +++ b/cmd/plakar/subcommands/man/docs/info.md @@ -98,4 +98,4 @@ The **plakar info** utility exits 0 on success, and >0 if an error plakar(1), plakar-snapshot(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/ls.md b/cmd/plakar/subcommands/man/docs/ls.md index 719b5492..9076c902 100644 --- a/cmd/plakar/subcommands/man/docs/ls.md +++ b/cmd/plakar/subcommands/man/docs/ls.md @@ -81,4 +81,4 @@ The **plakar ls** utility exits 0 on success, and >0 if an error oc plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/mount.md b/cmd/plakar/subcommands/man/docs/mount.md index f785b0b1..822b4b91 100644 --- a/cmd/plakar/subcommands/man/docs/mount.md +++ b/cmd/plakar/subcommands/man/docs/mount.md @@ -60,4 +60,4 @@ The **plakar mount** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/restore.md b/cmd/plakar/subcommands/man/docs/restore.md index 2a75f06e..f4ecdbd7 100644 --- a/cmd/plakar/subcommands/man/docs/restore.md +++ b/cmd/plakar/subcommands/man/docs/restore.md @@ -87,4 +87,4 @@ The **plakar restore** utility exits 0 on success, and >0 if an err plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/rm.md b/cmd/plakar/subcommands/man/docs/rm.md index 6c93ffe6..8cbf5c4f 100644 --- a/cmd/plakar/subcommands/man/docs/rm.md +++ b/cmd/plakar/subcommands/man/docs/rm.md @@ -80,4 +80,4 @@ The **plakar rm** utility exits 0 on success, and >0 if an error oc plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/server.md b/cmd/plakar/subcommands/man/docs/server.md index 385690e6..4cb5d584 100644 --- a/cmd/plakar/subcommands/man/docs/server.md +++ b/cmd/plakar/subcommands/man/docs/server.md @@ -74,4 +74,4 @@ The **plakar server** utility exits 0 on success, and >0 if an erro plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/stdio.md b/cmd/plakar/subcommands/man/docs/stdio.md index a98c4f21..5f8c06da 100644 --- a/cmd/plakar/subcommands/man/docs/stdio.md +++ b/cmd/plakar/subcommands/man/docs/stdio.md @@ -55,4 +55,4 @@ The **plakar stdio** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/sync.md b/cmd/plakar/subcommands/man/docs/sync.md index e2bbff22..0fdff820 100644 --- a/cmd/plakar/subcommands/man/docs/sync.md +++ b/cmd/plakar/subcommands/man/docs/sync.md @@ -88,4 +88,4 @@ The **plakar sync** utility exits 0 on success, and >0 if an error plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/ui.md b/cmd/plakar/subcommands/man/docs/ui.md index c975945c..f7c8ca59 100644 --- a/cmd/plakar/subcommands/man/docs/ui.md +++ b/cmd/plakar/subcommands/man/docs/ui.md @@ -61,4 +61,4 @@ The **plakar ui** utility exits 0 on success, and >0 if an error oc plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/verify.md b/cmd/plakar/subcommands/man/docs/verify.md index 97fb3cfd..e7201bd6 100644 --- a/cmd/plakar/subcommands/man/docs/verify.md +++ b/cmd/plakar/subcommands/man/docs/verify.md @@ -75,4 +75,4 @@ The **plakar verify** utility exits 0 on success, and >0 if an erro plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/man/docs/version.md b/cmd/plakar/subcommands/man/docs/version.md index c475cf22..8124257e 100644 --- a/cmd/plakar/subcommands/man/docs/version.md +++ b/cmd/plakar/subcommands/man/docs/version.md @@ -46,4 +46,4 @@ The **plakar version** utility exits 0 on success, and >0 if an err plakar(1) -OpenBSD 7.6 - November 12, 2024 +macOS 15.0 - November 12, 2024 diff --git a/cmd/plakar/subcommands/tags/tags.1 b/cmd/plakar/subcommands/tags/tags.1 new file mode 100644 index 00000000..6bf9da88 --- /dev/null +++ b/cmd/plakar/subcommands/tags/tags.1 @@ -0,0 +1,75 @@ +.Dd November 13, 2024 +.Dt PLAKAR TAGS 1 +.Os +.Sh NAME +.Nm plakar_tags +.Nd Display tags or related information in a Plakar repository +.Sh SYNOPSIS +.Nm +.Op Fl display +.Op Ar tags|count|snapshots +.Sh DESCRIPTION +The +.Nm +command is used to display information about tags in a Plakar repository, including a list of tags, a count of their occurrences, or associated snapshots. + +.Bl -tag -width Ds +.It Fl display +Specifies the type of output for the tag display. Valid options are: +.Bl -tag -width tags -compact +.It tags +Lists all tags (default). +.It count +Displays each tag with a count of associated snapshots. +.It snapshots +Shows each tag with a list of associated snapshot IDs. +.El +.El + +.Sh ARGUMENTS +.Bl -tag -width Ds +.It Ar tags|count|snapshots +This argument, when used with the +.Fl display +flag, controls the output type: +.Bl -tag -width tags -compact +.It tags +Outputs all tags in alphabetical order. +.It count +Displays tags with a count of associated snapshots. +.It snapshots +Lists each tag with associated snapshot IDs. +.El +.El + +.Sh EXAMPLES +To illustrate usage: + +.Bl -tag -width Ds +.It Basic example: +.Bd -literal -offset indent +plakar tags -display tags +.Ed + +.It Example showing tag counts: +.Bd -literal -offset indent +plakar tags -display count +.Ed + +.It Example with tag snapshots: +.Bd -literal -offset indent +plakar tags -display snapshots +.Ed +.El + +.Sh DIAGNOSTICS +.Ex -std +.Bl -tag -width Ds +.It 0 +Command completed successfully. +.It 1 +An unsupported display option was specified. +.El + +.Sh SEE ALSO +.Xr plakar 1 diff --git a/cmd/plakar/subcommands/tags/tags.go b/cmd/plakar/subcommands/tags/tags.go new file mode 100644 index 00000000..b86c0151 --- /dev/null +++ b/cmd/plakar/subcommands/tags/tags.go @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Gilles Chehade + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package ls + +import ( + "flag" + "fmt" + "os" + "sort" + "strings" + + "github.com/PlakarKorp/plakar/cmd/plakar/subcommands" + "github.com/PlakarKorp/plakar/context" + "github.com/PlakarKorp/plakar/repository" + "github.com/PlakarKorp/plakar/snapshot" +) + +func init() { + subcommands.Register("tags", cmd_tags) +} + +func cmd_tags(ctx *context.Context, repo *repository.Repository, args []string) int { + var opt_display string + flags := flag.NewFlagSet("tags", flag.ExitOnError) + flags.StringVar(&opt_display, "display", "tags", "display tags") + flags.Parse(args) + + if opt_display != "tags" && opt_display != "count" && opt_display != "snapshots" { + fmt.Fprintf(os.Stderr, "unsupported display option: %s\n", opt_display) + return 1 + } + + list_tags(repo, opt_display) + return 0 +} + +func list_tags(repo *repository.Repository, display string) { + tags := make(map[string][][32]byte) + for snapshotID := range repo.ListSnapshots() { + snap, err := snapshot.Load(repo, snapshotID) + if err != nil { + continue + } + for _, tag := range snap.Header.Tags { + if _, ok := tags[tag]; !ok { + tags[tag] = make([][32]byte, 0) + } + tags[tag] = append(tags[tag], snapshotID) + } + } + + tagsList := make([]string, 0, len(tags)) + for tag := range tags { + tagsList = append(tagsList, tag) + } + sort.Slice(tagsList, func(i, j int) bool { + return tagsList[i] < tagsList[j] + }) + + if display == "tags" { + fmt.Println(strings.Join(tagsList, "\n")) + } else if display == "count" { + for _, tag := range tagsList { + fmt.Printf("%s: %d\n", tag, len(tags[tag])) + } + } else if display == "snapshots" { + for _, tag := range tagsList { + fmt.Printf("%s:\n", tag) + for _, snapshotID := range tags[tag] { + fmt.Printf(" - %x\n", snapshotID[:4]) + } + } + } +} From d043d4fbbd04775fff92b9824da68d44a507324d Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Wed, 13 Nov 2024 00:59:41 +0100 Subject: [PATCH 2/2] update --- cmd/plakar/subcommands/man/docs/tags.md | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 cmd/plakar/subcommands/man/docs/tags.md diff --git a/cmd/plakar/subcommands/man/docs/tags.md b/cmd/plakar/subcommands/man/docs/tags.md new file mode 100644 index 00000000..7301f986 --- /dev/null +++ b/cmd/plakar/subcommands/man/docs/tags.md @@ -0,0 +1,87 @@ +PLAKAR(TAGS) - TAGS (1) + +# NAME + +**plakar\_tags** - Display tags or related information in a Plakar repository + +# SYNOPSIS + +**plakar\_tags** +\[**-display**] +\[*tags|count|snapshots*] + +# DESCRIPTION + +The +**plakar\_tags** +command is used to display information about tags in a Plakar repository, including a list of tags, a count of their occurrences, or associated snapshots. + +**-display** + +> Specifies the type of output for the tag display. Valid options are: + +> tags + +> > Lists all tags (default). + +> count + +> > Displays each tag with a count of associated snapshots. + +> snapshots + +> > Shows each tag with a list of associated snapshot IDs. + +# ARGUMENTS + +*tags|count|snapshots* + +> This argument, when used with the +> **-display** +> flag, controls the output type: + +> tags + +> > Outputs all tags in alphabetical order. + +> count + +> > Displays tags with a count of associated snapshots. + +> snapshots + +> > Lists each tag with associated snapshot IDs. + +# EXAMPLES + +To illustrate usage: + +Basic example: + +> > plakar tags -display tags + +Example showing tag counts: + +> > plakar tags -display count + +Example with tag snapshots: + +> > plakar tags -display snapshots + +# DIAGNOSTICS + +The **plakar\_tags** utility exits 0 on success, and >0 if an error occurs. + +0 + +> Command completed successfully. + +1 + +> An unsupported display option was specified. + +# SEE ALSO + +plakar(1) + +macOS 15.0 - November 13, 2024