-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cbd4d1
commit 3a6fd86
Showing
5 changed files
with
228 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
namespace SteamPrefill.CliCommands | ||
{ | ||
[UsedImplicitly] | ||
[Command("status", Description = "List all currently selected apps and the used disk space.")] | ||
public class StatusCommand : ICommand | ||
{ | ||
[CommandOption("no-ansi", | ||
Description = "Application output will be in plain text. " + | ||
"Should only be used if terminal does not support Ansi Escape sequences, or when redirecting output to a file.", | ||
Converter = typeof(NullableBoolConverter))] | ||
public bool? NoAnsiEscapeSequences { get; init; } | ||
|
||
[CommandOption("os", Description = "Specifies which operating system(s) games should be downloaded for. Can be windows/linux/macos", | ||
Converter = typeof(OperatingSystemConverter), Validators = new[] { typeof(OperatingSystemValidator) })] | ||
public IReadOnlyList<OperatingSystem> OperatingSystems { get; init; } = new List<OperatingSystem> { OperatingSystem.Windows }; | ||
|
||
[CommandOption("sort-order", Description = "Specifies in which way the data should be sorted. Can be ascending/descending", | ||
Converter = typeof(SortOrderConverter), Validators = new [] { typeof(SortOrderValidator) })] | ||
public SortOrder SortOrder { get; init; } = SortOrder.Ascending; | ||
|
||
[CommandOption("sort-column", Description = "Specifies by which column the data should be sorted. Can be app/size", | ||
Validators = new [] { typeof(SortColumnValidator) })] | ||
public string SortColumn { get; init; } = "app"; | ||
|
||
private IAnsiConsole _ansiConsole; | ||
|
||
public async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
_ansiConsole = console.CreateAnsiConsole(); | ||
// Property must be set to false in order to disable ansi escape sequences | ||
_ansiConsole.Profile.Capabilities.Ansi = !NoAnsiEscapeSequences ?? true; | ||
|
||
var downloadArgs = new DownloadArguments | ||
{ | ||
NoCache = AppConfig.NoLocalCache, | ||
OperatingSystems = OperatingSystems.ToList() | ||
}; | ||
|
||
using var steamManager = new SteamManager(_ansiConsole, downloadArgs); | ||
ValidateUserHasSelectedApps(steamManager); | ||
|
||
try | ||
{ | ||
await steamManager.InitializeAsync(); | ||
await steamManager.CurrentlyDownloadedAsync(SortOrder, SortColumn); | ||
} | ||
finally | ||
{ | ||
steamManager.Shutdown(); | ||
} | ||
} | ||
|
||
// Validates that the user has selected at least 1 app | ||
private void ValidateUserHasSelectedApps(SteamManager steamManager) | ||
{ | ||
var userSelectedApps = steamManager.LoadPreviouslySelectedApps(); | ||
|
||
if (!userSelectedApps.Any()) | ||
{ | ||
// User hasn't selected any apps yet | ||
_ansiConsole.MarkupLine(Red("No apps have been selected for benchmark! At least 1 app is required!")); | ||
_ansiConsole.Markup(Red($"See flags {LightYellow("--appid")}, {LightYellow("--all")} and {LightYellow("--use-selected")} to interactively choose which apps to prefill")); | ||
|
||
throw new CommandException(".", 1, true); | ||
} | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace SteamPrefill.Models.Enums | ||
{ | ||
[Intellenum(typeof(string))] | ||
public sealed partial class SortOrder | ||
{ | ||
public static readonly SortOrder Ascending = new("ascending"); | ||
public static readonly SortOrder Descending = new("descending"); | ||
} | ||
} |
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,30 @@ | ||
# status | ||
|
||
## Overview | ||
|
||
Lists all selected apps and their disk usage. | ||
|
||
----- | ||
|
||
## Example usage | ||
|
||
Checking the `status` is as simple as running the following from the terminal: | ||
```powershell | ||
./{{prefillName}} status | ||
``` | ||
|
||
### Customized the sorting | ||
|
||
An advanced usage with customized sorting can be used as the following from the terminal: | ||
```powershell | ||
./{{prefillName}} status --sort-order descending --sort-column size | ||
``` | ||
|
||
## Options | ||
|
||
| Option | | Values | Default | | | ||
| --------------- | --- | --------------------- | ------------- | --- | | ||
| --os | | windows, linux, macos | **windows** | Specifies which operating system(s) chunks should be filtered for. | | ||
| --no-ansi | | | | Application output will be in plain text, rather than using the visually appealing colors and progress bars. Should only be used if terminal does not support Ansi Escape sequences, or when redirecting output to a file. | | ||
| --sort-order | | ascending, descending | **ascending** | Specifies which sorting should be used for the data. | | ||
| --sort-column | | app, size | **app** | Specifies which column should be used for the sorting. | |