Skip to content

Commit b0eb886

Browse files
authored
Merge pull request #12 from dmnyu/validation
v0.2.0
2 parents 0d1538e + 5df48b3 commit b0eb886

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+684
-242
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*/bin/*
33
*/obj/*
44
/*/Properties/launchSettings.json
5-
*.csproj.user
5+
bagit.net.cli/bagit.net.cli.csproj.user
66
bagit.net/docs/*.md
77
*/dist/*
8+
*/Properties/*

README.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,82 @@
11
# bagit.net
22

3-
**bagit.net** is a C# implementation of the [BagIt specification (RFC 8493)](https://datatracker.ietf.org/doc/html/rfc8493). It allows you to create BagIt bags—structured file collections with checksums for reliable storage and transfer of digital content. It currently consists of a core library `bagit.net` and cli application `bagit.net.cli` for Linux and Windows
3+
**bagit.net** is a C# implementation of the [BagIt specification (RFC 8493)](https://datatracker.ietf.org/doc/html/rfc8493). It allows you to create BagIt bags—structured file collections with checksums for reliable storage and transfer of digital content. It currently consists of a core library `bagit.net` and CLI application `bagit.net.cli` for Linux and Windows
44

5-
[![Release](https://img.shields.io/badge/release-v0.1.0--alpha.1-blue)](https://github.com/dmnyu/bagit.net/releases/v0.1.0-alpha.1)
5+
[![Release](https://img.shields.io/badge/release-v0.2.0--alpha.1-blue)](https://github.com/dmnyu/bagit.net/releases/v0.2.0-alpha.1)
66

7-
> ⚠️ **Note:** This project is in early development and currently supports only the creation of bagit bags.
7+
> ⚠️ **Note:** This project is in early development and currently support the creation and validation of BagIt formatted bags.
88
9+
## bagit.net.cli
10+
## bagit.net Commands
11+
### create
12+
Create a Bagit Formatted Bag from a directory.
13+
#### options
14+
- **--algorithm**: specify the checksum algorithm to use: md5, sha1, sha256 (default), sha384, and sha512
15+
- **--log**: specify the location to write logging to (default stdout).
16+
#### usage
17+
```bash
18+
# Create a bag with default SHA-256 checksums
19+
bagit.net create /path/to/directory
920

21+
# Create a bag using MD5 checksums
22+
bagit.net create --algorithm md5 /path/to/directory
1023

11-
## bagit.net.cli
12-
### Binary Installation
24+
# Log to a file
25+
bagit.net create --log bagit.net.log /path/to/directory
26+
```
27+
28+
### validate
29+
Validate a Bagit Formatted Bag
30+
#### options
31+
- **--fast**: specify to validate a bag based on payload-oxum only
32+
- **--log**: specify the location to write logging to (default stdout).
33+
#### usage
34+
```bash
35+
# Validate a bag
36+
bagit.net validate /path/to/directory
1337

38+
# Validate a bag with logging to file
39+
bagit.net validate --log bagit.net.log /path/to/directory
1440

15-
### Linux
41+
# Fast Validate
42+
bagit.net validate --fast /path/to/directory
43+
```
44+
### help
45+
Print the help message
1646

47+
#### usage
1748
```bash
18-
wget https://github.com/dmnyu/bagit.net/releases/download/v0.1.0-alpha.1/bagit.net.cli-linux-v0.1.0-alpha.1.tgz
19-
tar xvzf bagit.net.cli-linux-v0.1.0-alpha.1.tgz
49+
bagit.net help
50+
```
51+
> **Tip:** including --help or -h in any command will print the help screen
52+
53+
### Binary Installation
54+
55+
#### Linux
56+
```bash
57+
wget https://github.com/dmnyu/bagit.net/releases/download/v0.2.0-alpha.1/bagit.net.cli-linux-v0.2.0-alpha.1.tgz
58+
tar xvzf bagit.net.cli-linux-v0.2.0-alpha.1.tgz
2059
cd bagit.net.cli
2160
sudo ./install.sh
2261
bagit.net --help
2362
```
2463

2564
**Linux / SELinux Notes**
26-
2765
bagit.net single-file self-contained binaries require the ability to create and execute temporary files. On RHEL/CentOS systems with SELinux or noexec restrictions on /tmp, these binaries will not run.
2866

29-
30-
### Windows
31-
67+
#### Windows
3268
```powershell
33-
Invoke-WebRequest -Uri https://github.com/dmnyu/bagit.net/releases/download/v0.1.0-alpha.1/bagit.net.cli-win-v0.1.0-alpha.1.zip -OutFile bagit.net.cli-win-v0.1.0-alpha.1.zip
34-
Expand-Archive bagit.net.cli-win-v0.1.0-alpha.1.zip -DestinationPath .
69+
Invoke-WebRequest -Uri https://github.com/dmnyu/bagit.net/releases/download/v0.2.0-alpha.1/bagit.net.cli-win-v0.2.0-alpha.1.zip -OutFile bagit.net.cli-win-v0.2.0-alpha.1.zip
70+
Expand-Archive bagit.net.cli-win-v0.2.0-alpha.1.zip -DestinationPath .
3571
cd .\bagit.net.cli
36-
"C:\Program Files\BagIt.NET\bagit.net.exe" --help
72+
.\bagit.net.exe" --help
3773
.\install.ps1
74+
%LOCALAPPDATA%\bagit.net\bagit.net --version
3875
```
3976
> **Tip:** After installing on Windows, you can run `bagit.net` from any directory by adding `%LOCALAPPDATA%\bagit.net` to your user PATH in System Properties.
4077
4178

42-
## Usage Examples
43-
```bash
44-
# Create a bag with default SHA-256 checksums
45-
bagit.net create /path/to/directory
46-
47-
# Create a bag using MD5 checksums
48-
bagit.net create --algorithm md5 /path/to/directory
49-
50-
# Log to a file
51-
bagit.net create --log bagit.net.log /path/to/directory
5279

53-
# View the Help Page
54-
bagit.net --help
55-
```
5680

5781
## Additional Notes
5882

bagit.net.cli/BagitCLI.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int Main(string[] args)
3232

3333
if (args[0] == "--version")
3434
{
35-
AnsiConsole.MarkupLine($"bagit.net {Bagit.VERSION}");
35+
AnsiConsole.MarkupLine($"bagit.net v{Bagit.VERSION}");
3636
return 0;
3737
}
3838

@@ -42,7 +42,9 @@ static int Main(string[] args)
4242
config.AddCommand<BagCommand>("create")
4343
.WithDescription("Create a BagIt bag from a directory");
4444
config.AddCommand<HelpCommand>("help")
45-
.WithDescription("display the help page");
45+
.WithDescription("Display the help page");
46+
config.AddCommand<ValidateCommand>("validate")
47+
.WithDescription("Validate a BagIt bag");
4648
});
4749

4850
return app.Run(args);

bagit.net.cli/Commands/HelpCommand.cs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,81 @@ namespace bagit.net.cli.Commands;
66
class HelpCommand : Command<HelpCommand.Settings>
77
{
88
public class Settings : CommandSettings { }
9+
910
public override int Execute(CommandContext? context, Settings settings, CancellationToken cancellationToken)
1011
{
1112
// Header
1213
AnsiConsole.MarkupLine($"bagit.net.cli v{Bagit.VERSION}");
13-
AnsiConsole.WriteLine("- a BagIt (RFC 8493) tool for creating and validating bags");
14+
AnsiConsole.MarkupLine("- a BagIt (RFC 8493) tool for creating and validating bags");
1415
AnsiConsole.WriteLine();
1516

1617
// Usage
1718
AnsiConsole.MarkupLine("[lime]USAGE:[/]");
18-
AnsiConsole.MarkupLine(" bagit.net.cli.exe [cyan][[COMMAND]][/] [darkorange][[OPTIONS]][/]");
19+
AnsiConsole.MarkupLine(" bagit.net [cyan][[COMMAND]][/] [darkorange][[OPTIONS]][/]");
1920
AnsiConsole.WriteLine();
2021

2122
// Commands
2223
AnsiConsole.MarkupLine("[cyan]COMMANDS:[/]");
23-
AnsiConsole.MarkupLine(" [cyan]create[/]\tcreate a bag from an existing directory");
24-
AnsiConsole.MarkupLine(" [cyan]help[/]\t\tdisplay the help page");
24+
var table = new Table()
25+
.HideHeaders()
26+
.NoBorder()
27+
.AddColumn(new TableColumn(string.Empty))
28+
.AddColumn(new TableColumn(string.Empty));
29+
30+
table.AddRow("[cyan]create[/]", "create a bag from an existing directory");
31+
table.AddRow("[cyan]validate[/]", "validate an existing bag");
32+
table.AddRow("[cyan]help[/]", "display the help page");
33+
34+
AnsiConsole.Write(table);
2535
AnsiConsole.WriteLine();
2636

27-
// Create Command
37+
// CREATE Command Section
2838
AnsiConsole.MarkupLine("[cyan]CREATE COMMAND[/]");
2939
AnsiConsole.MarkupLine("[lime]USAGE:[/]");
30-
AnsiConsole.MarkupLine(" bagit.net.cli.exe [cyan]create[/] [darkorange][[OPTIONS]][/] [red]<directory>[/]");
40+
AnsiConsole.MarkupLine(" bagit.net [cyan]create[/] [darkorange][[OPTIONS]][/] [red]<directory>[/]");
41+
AnsiConsole.WriteLine();
42+
43+
AnsiConsole.MarkupLine("[darkorange]OPTIONS:[/]");
44+
var createOptions = new Table()
45+
.HideHeaders()
46+
.NoBorder()
47+
.AddColumn(new TableColumn(string.Empty))
48+
.AddColumn(new TableColumn(string.Empty));
49+
50+
createOptions.AddRow("--algorithm", "checksum algorithm: md5, sha1, sha256, sha384, sha512 (default: sha256)");
51+
createOptions.AddRow("--log", "path to log file (default: stdout)");
52+
53+
AnsiConsole.Write(createOptions);
54+
AnsiConsole.WriteLine();
55+
AnsiConsole.WriteLine();
56+
57+
// VALIDATE Command Section
58+
AnsiConsole.MarkupLine("[cyan]VALIDATE COMMAND[/]");
59+
AnsiConsole.MarkupLine("[lime]USAGE:[/]");
60+
AnsiConsole.MarkupLine(" bagit.net [cyan]validate[/] [darkorange][[OPTIONS]][/] [red]<directory>[/]");
3161
AnsiConsole.WriteLine();
3262

33-
// Create Options
34-
AnsiConsole.MarkupLine("[darkorange]OPTIONS[/]");
35-
AnsiConsole.MarkupLine(" --algorithm\tchecksum algorithm, Values: md5, sha1, sha256, sha384, sha512 (default: sha256)");
36-
AnsiConsole.MarkupLine(" --log\t\tpath to log file (default: stdout)");
63+
AnsiConsole.MarkupLine("[darkorange]OPTIONS:[/]");
64+
var validateOptions = new Table()
65+
.HideHeaders()
66+
.NoBorder()
67+
.AddColumn(new TableColumn(string.Empty))
68+
.AddColumn(new TableColumn(string.Empty));
69+
70+
validateOptions.AddRow("--fast", "validate only the bag's Payload-Oxum");
71+
validateOptions.AddRow("--log", "path to log file (default: stdout)");
72+
73+
AnsiConsole.Write(validateOptions);
3774
AnsiConsole.WriteLine();
3875
AnsiConsole.WriteLine();
3976

4077
// Examples
41-
AnsiConsole.MarkupLine("[magenta1]Examples:[/]");
42-
AnsiConsole.MarkupLine(" bagit.net.cli.exe [cyan]create[/] [darkorange]--algorithm md5[/] [red]<directory>[/]");
43-
AnsiConsole.MarkupLine(" bagit.net.cli.exe [cyan]create[/] [darkorange]--log bagit.net.log[/] [red]<directory>[/]");
78+
AnsiConsole.MarkupLine("[magenta1]EXAMPLES:[/]");
79+
AnsiConsole.MarkupLine(" bagit.net [cyan]create[/] [darkorange]--algorithm md5[/] [red]<directory>[/]");
80+
AnsiConsole.MarkupLine(" bagit.net [cyan]create[/] [darkorange]--log bagit.net.log[/] [red]<directory>[/]");
81+
AnsiConsole.MarkupLine(" bagit.net [cyan]validate[/] [darkorange]--log bagit.net.log[/] [red]<directory>[/]");
82+
AnsiConsole.MarkupLine(" bagit.net [cyan]validate[/] [darkorange]--fast[/] [red]<directory>[/]");
4483

4584
return 0;
4685
}
47-
48-
}
86+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Microsoft.Extensions.Logging;
2+
using Spectre.Console;
3+
using Spectre.Console.Cli;
4+
using System.ComponentModel;
5+
6+
namespace bagit.net.cli.Commands
7+
{
8+
class ValidateCommand : Command<ValidateCommand.Settings>
9+
{
10+
public class Settings : CommandSettings
11+
{
12+
[CommandOption("--log")]
13+
public string? logFile { get; set; }
14+
15+
[CommandOption("--fast")]
16+
public bool Fast { get; set; }
17+
18+
[CommandArgument(0, "[directory]")]
19+
[Description("Path to the bag directory to validate.")]
20+
public string? Directory { get; set; }
21+
}
22+
23+
public override int Execute(CommandContext context, Settings settings, CancellationToken cancellationToken)
24+
{
25+
if (string.IsNullOrWhiteSpace(settings.Directory))
26+
{
27+
AnsiConsole.MarkupLine("[red][bold]ERROR:[/][/]");
28+
AnsiConsole.MarkupLine("[red]a directory to a BagIt bag must be specified when creating a bag[/]\n");
29+
BagitCLI.app.Run(new string[] { "help" }, cancellationToken);
30+
return 1;
31+
}
32+
33+
var bagPath = Path.GetFullPath(settings.Directory);
34+
if (!Directory.Exists(bagPath))
35+
{
36+
AnsiConsole.MarkupLine("[red][bold]ERROR:[/][/]");
37+
AnsiConsole.MarkupLine($"[red]the directory {bagPath} does not exist[/]\n");
38+
BagitCLI.app.Run(new string[] { "help" }, cancellationToken);
39+
return 1;
40+
}
41+
42+
if (!string.IsNullOrWhiteSpace(settings.logFile))
43+
{
44+
AnsiConsole.MarkupLine($"bagit.net.cli v{Bagit.VERSION}");
45+
AnsiConsole.MarkupLine($"Logging to {settings.logFile}");
46+
}
47+
Bagit.InitLogger(settings.logFile);
48+
Bagit.Logger.LogInformation($"Using bagit.net v{Bagit.VERSION}");
49+
50+
//start the validation
51+
var validator = new Validator();
52+
validator.ValidateBag(bagPath, settings.Fast);
53+
return 0;
54+
}
55+
}
56+
}
57+
58+

bagit.net.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
.gitignore = .gitignore
1616
bagitnet_roadmap.md = bagitnet_roadmap.md
1717
LICENSE.txt = LICENSE.txt
18+
improvements.md = improvements.md
1819
README.md = README.md
1920
EndProjectSection
2021
EndProject
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bag-Software-Agent: bagit.py v1.9.0 <https://github.com/LibraryOfCongress/bagit-python>
2+
Bagging-Date: 2025-11-20
3+
Payload-Oxum: 6.1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BagIt-Version: 0.97
2+
Tag-File-Character-Encoding: UTF-8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 data/hello.txt

0 commit comments

Comments
 (0)