From 1d9b57f7340b237a3ebecbfed0b970f403916a57 Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Tue, 4 Oct 2022 17:51:31 +0000 Subject: [PATCH] (#2829) Adds Basic choco license Command (WIP) --- src/chocolatey/chocolatey.csproj | 1 + .../commands/ChocolateyLicenseCommand.cs | 89 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/chocolatey/infrastructure.app/commands/ChocolateyLicenseCommand.cs diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index c59d36b1e9..ad6b3992a5 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -115,6 +115,7 @@ + diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyLicenseCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyLicenseCommand.cs new file mode 100644 index 0000000000..23eb468492 --- /dev/null +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyLicenseCommand.cs @@ -0,0 +1,89 @@ +// Copyright © 2017 - 2021 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.app.commands +{ + using chocolatey.infrastructure.app.attributes; + using chocolatey.infrastructure.app.configuration; + using chocolatey.infrastructure.commandline; + using chocolatey.infrastructure.commands; + using chocolatey.infrastructure.filesystem; + using chocolatey.infrastructure.licensing; + using chocolatey.infrastructure.logging; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + + [CommandFor("license", "Retrieve or modify the Chocolatey License")] + class ChocolateyLicenseCommand : ICommand + { + public void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration) + { + // We don't currently expect to have any arguments + return; + } + + public void handle_additional_argument_parsing(IList unparsedArguments, ChocolateyConfiguration configuration) + { + // We don't currently expect to have any additional arguments + return; + } + + public void handle_validation(ChocolateyConfiguration configuration) + { + // We don't currently accept any arguments, so there is no validation + return; + } + + public void help_message(ChocolateyConfiguration configuration) + { + this.Log().Info(ChocolateyLoggers.Important, "License Command"); + this.Log().Info(@" +Chocolatey will do license things. +"); + } + + public bool may_require_admin_access() + { + return false; + } + + public void noop(ChocolateyConfiguration configuration) + { + return; + } + + public void run(ChocolateyConfiguration config) + { + var ourLicense = LicenseValidation.validate(); + + if (config.RegularOutput) + { + this.Log().Info("We have found a{0}valid license for Chocolatey {1}, which expires {2}".format_with((ourLicense.IsValid ? " " : "n in"), ourLicense.LicenseType, ourLicense.ExpirationDate)); + this.Log().Info("Registered to: {0}".format_with(ourLicense.Name)); + this.Log().Info("Expiration Date: {0} UTC".format_with(ourLicense.ExpirationDate)); + this.Log().Info("License type: {0}".format_with(ourLicense.LicenseType)); + this.Log().Info("Node Count: {0}".format_with("")); + } + else + { + // Name, LicenseType, ExpirationDate, NodeCount + this.Log().Info("{0}|{1}|{2}|{3}".format_with(ourLicense.Name, ourLicense.LicenseType, ourLicense.ExpirationDate, "0")); + } + } + } +}