Skip to content

Commit

Permalink
add - doc - Added a property for "-set" switch
Browse files Browse the repository at this point in the history
---

We've added a property that allows your commands to determine whether the -set switch has been passed or not.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 19, 2024
1 parent 9ba180a commit f4ff2ca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/Nitrocid/Nitrocid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<NitrocidModAPIVersionMajor>3.0.25</NitrocidModAPIVersionMajor>

<!-- Increment NitrocidModAPIVersionChangeset every time there is a breaking change or an API addition in the N-KS API. -->
<NitrocidModAPIVersionChangeset>430</NitrocidModAPIVersionChangeset>
<NitrocidModAPIVersionChangeset>431</NitrocidModAPIVersionChangeset>

<!-- To be installed to the file version -->
<NitrocidModAPIVersion>$(NitrocidModAPIVersionMajor).$(NitrocidModAPIVersionChangeset)</NitrocidModAPIVersion>
Expand Down
5 changes: 4 additions & 1 deletion public/Nitrocid/Shell/ShellBase/Commands/CommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ private static void ExecuteCommand(CommandExecutorParameters ThreadParams, Comma
if (argSatisfied)
{
// Prepare the command parameter instance
var parameters = new CommandParameters(StrArgs, Args, StrArgsOrig, ArgsOrig, Switches, Command);
var parameters = new CommandParameters(StrArgs, Args, StrArgsOrig, ArgsOrig, Switches, Command)
{
SwitchSetPassed = containsSetSwitch
};

// Now, get the base command and execute it
DebugWriter.WriteDebug(DebugLevel.I, "Really executing command {0} with args {1}", Command, StrArgs);
Expand Down
4 changes: 4 additions & 0 deletions public/Nitrocid/Shell/ShellBase/Commands/CommandParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public class CommandParameters
/// </summary>
public string[] SwitchesList =>
listSwitchesOnly;
/// <summary>
/// Whether the <c>-set=var</c> switch has been passed to the command or not
/// </summary>
public bool SwitchSetPassed { get; internal set; }

internal CommandParameters(string stringArgs, string[] listArgsOnly, string stringArgsOrig, string[] listArgsOnlyOrig, string[] listSwitchesOnly, string commandName)
{
Expand Down
9 changes: 9 additions & 0 deletions public/Nitrocid/Shell/Shells/UESH/Commands/Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.ConsoleBase.Colors;
using Nitrocid.ConsoleBase.Writers;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;

namespace Nitrocid.Shell.Shells.UESH.Commands
Expand All @@ -32,6 +36,11 @@ class SetCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
if (!parameters.SwitchSetPassed)
{
TextWriters.Write(Translate.DoTranslation("You must pass the -set switch with the variable that you want to set this value to."), KernelColorType.Error);
return KernelExceptionTools.GetErrorCode(KernelExceptionType.ShellOperation);
}
variableValue = parameters.ArgumentsList[0];
return 0;
}
Expand Down
9 changes: 9 additions & 0 deletions public/Nitrocid/Shell/Shells/UESH/Commands/SetRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Nitrocid.ConsoleBase.Colors;
using Nitrocid.ConsoleBase.Writers;
using Nitrocid.Kernel.Exceptions;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;

namespace Nitrocid.Shell.Shells.UESH.Commands
Expand All @@ -32,6 +36,11 @@ class SetRangeCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
if (!parameters.SwitchSetPassed)
{
TextWriters.Write(Translate.DoTranslation("You must pass the -set switch with the variable that you want to set this value to."), KernelColorType.Error);
return KernelExceptionTools.GetErrorCode(KernelExceptionType.ShellOperation);
}
variableValue = $"[{string.Join(", ", [.. parameters.ArgumentsList])}]";
return 0;
}
Expand Down

0 comments on commit f4ff2ca

Please sign in to comment.