-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from PlakarKorp/gchehade/plakar-tags
Gchehade/plakar tags
- Loading branch information
Showing
25 changed files
with
272 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2021 Gilles Chehade <[email protected]> | ||
* | ||
* 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]) | ||
} | ||
} | ||
} | ||
} |