Skip to content

Commit

Permalink
Add command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalnem committed Mar 15, 2024
1 parent cc4c336 commit 76050f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="8.0.2" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

</Project>
43 changes: 40 additions & 3 deletions Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
using Microsoft.Extensions.Logging.Abstractions;
using System.CommandLine;
using Microsoft.Extensions.Logging.Abstractions;

namespace Api;

public class Program
{
public static async Task Main(string[] args)
{
var username = Environment.GetEnvironmentVariable("BANDCAMP_USERNAME");
var password = Environment.GetEnvironmentVariable("BANDCAMP_PASSWORD");
var username = CreateOption("--username", "Your Bandcamp account username.");
var password = CreateOption("--password", "Your Bandcamp account password.");
var album = CreateOption("--album", "ID of the album you want to download.");

var listCommand = new RootCommand("List all albums in your Bandcamp collection.")
{
username,
password,
};

var downloadCommand = new Command("download", "Download the album with the specified ID.")
{
username,
password,
album
};

listCommand.AddCommand(downloadCommand);
listCommand.SetHandler(List, username, password);
downloadCommand.SetHandler(Download, username, password, album);

await listCommand.InvokeAsync(args);
}

private static async Task List(string username, string password)
{
using var client = new Client(username, password, NullLoggerFactory.Instance);

await foreach (var item in client.GetCollection())
Expand All @@ -20,4 +44,17 @@ public static async Task Main(string[] args)
Console.WriteLine($"{id,10} {artist}{album}");
}
}

private static void Download(string username, string password, string album)
{
throw new NotImplementedException();
}

private static Option<string> CreateOption(string name, string description)
{
return new Option<string>(name, description)
{
IsRequired = true
};
}
}

0 comments on commit 76050f7

Please sign in to comment.