diff --git a/src/WingetCreateCLI/Commands/BaseCommand.cs b/src/WingetCreateCLI/Commands/BaseCommand.cs
index 1b3e2049..69de1ba7 100644
--- a/src/WingetCreateCLI/Commands/BaseCommand.cs
+++ b/src/WingetCreateCLI/Commands/BaseCommand.cs
@@ -76,7 +76,7 @@ public abstract class BaseCommand
///
/// Gets the GitHubClient instance to use for interacting with GitHub from the CLI.
///
- protected GitHub GitHubClient { get; private set; }
+ internal GitHub GitHubClient { get; private set; }
///
/// Abstract method executing the command.
@@ -84,6 +84,54 @@ public abstract class BaseCommand
/// Boolean representing success or fail of the command.
public abstract Task Execute();
+ ///
+ /// Creates a new GitHub client using the provided or cached token if present.
+ /// If the requireToken bool is set to TRUE, OAuth flow can be launched to acquire a new token for the client.
+ /// The OAuth flow will only be launched if no token is provided in the command line and no token is present in the token cache.
+ ///
+ /// Boolean value indicating whether a token is required for the client and whether to initiate an OAuth flow.
+ /// A boolean value indicating whether a new GitHub client was created and accessed successfully.
+ public async Task LoadGitHubClient(bool requireToken = false)
+ {
+ bool isCacheToken = false;
+
+ if (string.IsNullOrEmpty(this.GitHubToken))
+ {
+ Logger.Trace("No token parameter, reading cached token");
+ this.GitHubToken = GitHubOAuth.ReadTokenCache();
+
+ if (string.IsNullOrEmpty(this.GitHubToken))
+ {
+ if (requireToken)
+ {
+ Logger.Trace("No token found in cache, launching OAuth flow");
+ if (!await this.GetTokenFromOAuth())
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ isCacheToken = true;
+ }
+ }
+
+ if (await this.CheckGitHubTokenAndSetClient())
+ {
+ return true;
+ }
+ else
+ {
+ if (isCacheToken)
+ {
+ GitHubOAuth.DeleteTokenCache();
+ }
+
+ return false;
+ }
+ }
+
///
/// Creates a formatted directory of manifest files from the manifest object models and saves the directory to a local path.
///
@@ -312,54 +360,6 @@ protected static void DisplayManifestPreview(Manifests manifests)
Console.WriteLine(manifests.DefaultLocaleManifest.ToYaml());
}
- ///
- /// Creates a new GitHub client using the provided or cached token if present.
- /// If the requireToken bool is set to TRUE, OAuth flow can be launched to acquire a new token for the client.
- /// The OAuth flow will only be launched if no token is provided in the command line and no token is present in the token cache.
- ///
- /// Boolean value indicating whether a token is required for the client and whether to initiate an OAuth flow.
- /// A boolean value indicating whether a new GitHub client was created and accessed successfully.
- protected async Task LoadGitHubClient(bool requireToken = false)
- {
- bool isCacheToken = false;
-
- if (string.IsNullOrEmpty(this.GitHubToken))
- {
- Logger.Trace("No token parameter, reading cached token");
- this.GitHubToken = GitHubOAuth.ReadTokenCache();
-
- if (string.IsNullOrEmpty(this.GitHubToken))
- {
- if (requireToken)
- {
- Logger.Trace("No token found in cache, launching OAuth flow");
- if (!await this.GetTokenFromOAuth())
- {
- return false;
- }
- }
- }
- else
- {
- isCacheToken = true;
- }
- }
-
- if (await this.CheckGitHubTokenAndSetClient())
- {
- return true;
- }
- else
- {
- if (isCacheToken)
- {
- GitHubOAuth.DeleteTokenCache();
- }
-
- return false;
- }
- }
-
///
/// Launches the GitHub OAuth flow and obtains a GitHub token.
///
diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs
index efd100f8..1767eb2e 100644
--- a/src/WingetCreateCLI/Commands/NewCommand.cs
+++ b/src/WingetCreateCLI/Commands/NewCommand.cs
@@ -141,17 +141,10 @@ public override async Task Execute()
if (this.WingetRepoOwner == DefaultWingetRepoOwner &&
this.WingetRepo == DefaultWingetRepo)
{
- if (await this.LoadGitHubClient())
- {
- if (!await this.PromptPackageIdentifierAndCheckDuplicates(manifests))
- {
- Console.WriteLine();
- Logger.ErrorLocalized(nameof(Resources.PackageIdAlreadyExists_Error));
- return false;
- }
- }
- else
+ if (!await this.PromptPackageIdentifierAndCheckDuplicates(manifests))
{
+ Console.WriteLine();
+ Logger.ErrorLocalized(nameof(Resources.PackageIdAlreadyExists_Error));
return false;
}
}
diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs
index 32dd610c..79f3f53d 100644
--- a/src/WingetCreateCLI/Commands/UpdateCommand.cs
+++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs
@@ -109,11 +109,6 @@ public override async Task Execute()
return false;
}
- if (!await this.LoadGitHubClient())
- {
- return false;
- }
-
Logger.DebugLocalized(nameof(Resources.RetrievingManifest_Message), this.Id);
string exactId;
diff --git a/src/WingetCreateCLI/Program.cs b/src/WingetCreateCLI/Program.cs
index 76f2ae9e..da6347eb 100644
--- a/src/WingetCreateCLI/Program.cs
+++ b/src/WingetCreateCLI/Program.cs
@@ -1,88 +1,110 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license.
-
-namespace Microsoft.WingetCreateCLI
-{
- using System;
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license.
+
+namespace Microsoft.WingetCreateCLI
+{
+ using System;
using System.Linq;
- using System.Threading.Tasks;
- using CommandLine;
+ using System.Threading.Tasks;
+ using CommandLine;
using CommandLine.Text;
- using Microsoft.WingetCreateCLI.Commands;
- using Microsoft.WingetCreateCLI.Logging;
- using Microsoft.WingetCreateCLI.Properties;
- using Microsoft.WingetCreateCLI.Telemetry;
- using Microsoft.WingetCreateCLI.Telemetry.Events;
+ using Microsoft.WingetCreateCLI.Commands;
+ using Microsoft.WingetCreateCLI.Logging;
+ using Microsoft.WingetCreateCLI.Properties;
+ using Microsoft.WingetCreateCLI.Telemetry;
+ using Microsoft.WingetCreateCLI.Telemetry.Events;
using Microsoft.WingetCreateCore.Common;
-
- ///
- /// Main entry class for the CLI.
- ///
- internal class Program
+
+ ///
+ /// Main entry class for the CLI.
+ ///
+ internal class Program
{
- private static async Task Main(string[] args)
+ private static async Task Main(string[] args)
{
Logger.Initialize();
UserSettings.FirstRunTelemetryConsent();
TelemetryEventListener.EventListener.IsTelemetryEnabled();
-
- string arguments = string.Join(' ', Environment.GetCommandLineArgs());
- Logger.Trace($"Command line args: {arguments}");
-
- Parser myParser = new Parser(config => config.HelpWriter = null);
+
+ string arguments = string.Join(' ', Environment.GetCommandLineArgs());
+ Logger.Trace($"Command line args: {arguments}");
+
+ Parser myParser = new Parser(config => config.HelpWriter = null);
var types = new Type[] { typeof(NewCommand), typeof(UpdateCommand), typeof(SubmitCommand), typeof(SettingsCommand), typeof(TokenCommand), typeof(CacheCommand) };
var parserResult = myParser.ParseArguments(args, types);
BaseCommand command = parserResult.MapResult(c => c as BaseCommand, err => null);
- if (command == null)
+ if (command == null)
{
DisplayHelp(parserResult as NotParsed