Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nullable stuff #253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ai/Program_AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public AiProgramData()

public bool DispatchRunCommand(ICommandValues values)
{
var command = values.GetCommand();
var command = values.GetCommandOrEmpty();
var root = command.Split('.').FirstOrDefault();

return root switch {
Expand All @@ -179,8 +179,8 @@ public bool DispatchRunCommand(ICommandValues values)

public bool DispatchParseCommand(INamedValueTokens tokens, ICommandValues values)
{
var command = values.GetCommand(null) ?? tokens.PeekNextToken();
var root = command.Split('.').FirstOrDefault();
var command = values.GetCommandOrDefault(null) ?? tokens.PeekNextToken();
var root = command?.Split('.').FirstOrDefault();

return root switch
{
Expand All @@ -207,7 +207,7 @@ public bool DispatchParseCommand(INamedValueTokens tokens, ICommandValues values

public bool DispatchParseCommandValues(INamedValueTokens tokens, ICommandValues values)
{
var root = values.GetCommandRoot();
var root = values.GetCommandRootOrEmpty();
return root switch
{
"init" => InitCommandParser.ParseCommandValues(tokens, values),
Expand Down
4 changes: 3 additions & 1 deletion src/ai/commands/chat_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Text.Json.Nodes;
using System.Threading;

namespace Azure.AI.Details.Common.CLI
{
Expand All @@ -35,7 +36,7 @@ internal ChatCommand(ICommandValues values) : base(values)

internal bool RunCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down Expand Up @@ -571,6 +572,7 @@ private void DisplayAssistantPromptLabel()

private void DisplayAssistantPromptTextStreaming(string text)
{
Thread.Sleep(30);
// do "tab" indentation when not quiet
Console.Write(!_quiet
? text.Replace("\n", "\n ")
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/dev_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal bool RunCommand()

private bool RunDevCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/eval_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal bool RunCommand()

private bool RunEvalCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/init_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private async Task<bool> RunInitCommand()
{
try
{
await DoCommand(_values.GetCommand());
await DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}
catch (ApplicationException ex)
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/language_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal bool RunCommand()

private bool RunLanguageCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/chat_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/dev_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/init_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();
switch (commandName)
{
case "init.aiservices":
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/language_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();
foreach (var command in _commands)
{
if (commandName == command.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();
switch (commandName)
{
case "wizard":
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/search_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/service_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/speech_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var check = string.Join(".", values.GetCommand()
var check = string.Join(".", values.GetCommandOrEmpty()
.Split('.')
.Take(2)
.ToArray());
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/test_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/tool_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();
foreach (var command in _commands)
{
if (commandName == command.name)
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/update_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/version_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();

switch (commandName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/parsers/vision_command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = {

private static IEnumerable<INamedValueTokenParser> GetCommandParsers(ICommandValues values)
{
var commandName = values.GetCommand();
var commandName = values.GetCommandOrEmpty();
switch (commandName)
{
case "vision.image":
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/scenario_wizard_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private async Task<bool> RunScenarioWizardCommand()
{
try
{
await DoCommand(_values.GetCommand());
await DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}
catch (ApplicationException)
Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/search_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal bool RunCommand()

private bool RunSearchCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/service_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal bool RunCommand()

private bool RunServiceCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/speech_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal bool RunCommand()

private bool RunSpeechCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/test_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal bool RunCommand()

private bool RunTestCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/tool_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal bool RunCommand()

private bool RunToolCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/version_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal VersionCommand(ICommandValues values) : base(values)

internal bool RunCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/commands/vision_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal bool RunCommand()

private bool RunVisionCommand()
{
DoCommand(_values.GetCommand());
DoCommand(_values.GetCommandOrEmpty());
return _values.GetOrDefault("passed", true);
}

Expand Down
5 changes: 2 additions & 3 deletions src/clis/vz/commands/image_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ private string GetVisionInputFromId(string id)
return input;
}

private string GetVisionInputFileFromId(string id)
private string? GetVisionInputFileFromId(string id)
{
string file;
var existing = FileHelpers.FindFileInDataPath(id, _values);
if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".png", _values);
if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".jpg", _values);
Expand All @@ -381,7 +380,7 @@ private string GetVisionInputFileFromId(string id)
}
}

file = existing;
var file = existing;
_values.Add("vision.input.file", file);
return file;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private static bool RunCommand(ICommandValues values)
else
{
outcome = Outcome.Failed;
errorInfo = $"Failed while running '{values.GetCommand()}' command";
errorInfo = $"Failed while running '{values.GetCommandOrEmpty()}' command";
}
}
catch (OperationCanceledException ex)
Expand All @@ -428,7 +428,7 @@ private static bool RunCommand(ICommandValues values)
{
_data?.Telemetry?.LogEvent(new CommandTelemetryEvent()
{
Type = values.GetCommand("unknown")!,
Type = values.GetCommandOrDefault("unknown")!,
Outcome = outcome,
ErrorInfo = errorInfo
});
Expand Down
6 changes: 3 additions & 3 deletions src/common/details/commands/command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool DispatchRunCommand(ICommandValues values)

public static bool DispatchRunCommand(ICommandValues values, Queue<ICommandValues>? queue, bool expandOk, bool parallelOk)
{
var command = values.GetCommand();
var command = values.GetCommandOrEmpty();

if (command == "config")
{
Expand Down Expand Up @@ -101,7 +101,7 @@ private static void ZipCommand(ICommandValues values, string zipAsFile, string t
var runScript = isWindows ? "run.cmd" : "run.sh";
if (verbose) Console.WriteLine($" Saving {runScript}... ");

var command = values.GetCommand();
var command = values.GetCommandOrEmpty();
var commandJob = "./" + command + ".job";

var runScriptPath = PathHelpers.Combine(tempDirectory, runScript)!;
Expand Down Expand Up @@ -613,7 +613,7 @@ private static bool RunCommandsOutOfProc(Queue<ICommandValues> queue, int maxPro
var fileNames = values.SaveAs(values.Names, Path.GetTempFileName());
var fileName = fileNames.Split(';').First();

var start = new ProcessStartInfo(Program.Exe, $"{values.GetCommand()} --nodefaults @{fileName}");
var start = new ProcessStartInfo(Program.Exe, $"{values.GetCommandOrEmpty()} --nodefaults @{fileName}");
start.UseShellExecute = false;

var process = Process.Start(start)!;
Expand Down
8 changes: 4 additions & 4 deletions src/common/details/commands/parsers/command_parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class CommandParser
{
protected static bool ParseCommandValues(string commandName, IEnumerable<INamedValueTokenParser> parsers, INamedValueTokens tokens, ICommandValues values)
{
return commandName != null && values.GetCommand()!.StartsWith(commandName) && ParseAllCommandValues(parsers, tokens, values);
return commandName != null && values.GetCommandOrEmpty()!.StartsWith(commandName) && ParseAllCommandValues(parsers, tokens, values);
}

protected static bool ParseCommand(string commandName, IEnumerable<INamedValueTokenParser> parsers, INamedValueTokens tokens, ICommandValues values)
Expand All @@ -84,7 +84,7 @@ protected static bool ParseCommand(string commandName, IEnumerable<INamedValueTo
protected static bool ParseCommands(IEnumerable<(string commandName, bool valuesRequired)> commands, IEnumerable<string> partials, INamedValueTokens tokens, ICommandValues values, Func<ICommandValues, IEnumerable<INamedValueTokenParser>> parsers)
{
return ParseCommandName(commands, partials, tokens, values) &&
ParseCommandDefaults(values.GetCommand()!, parsers(values), tokens, values) &&
ParseCommandDefaults(values.GetCommandOrEmpty()!, parsers(values), tokens, values) &&
ParseAllCommandValues(parsers(values), tokens, values);
}

Expand Down Expand Up @@ -124,7 +124,7 @@ protected static bool ParseCommandName(IEnumerable<(string name, bool requireCom

protected static bool ParseCommandName(string commandName, INamedValueTokens tokens, ICommandValues values, bool requireCommandValues = true)
{
if (commandName == values.GetCommand()) return true;
if (commandName == values.GetCommandOrEmpty()) return true;

var parsedDotName = commandName.Contains(".") && ParseCommandDotName(commandName, tokens, values, requireCommandValues);
var parsed = parsedDotName || ParseCommandName1(commandName, tokens, values, requireCommandValues);
Expand Down Expand Up @@ -152,7 +152,7 @@ protected static bool ParseCommandName1(string commandName, INamedValueTokens to
values.Add("x.command", commandName);
}

return values.Contains("x.command") && values.GetCommand() == commandName;
return values.Contains("x.command") && values.GetCommandOrEmpty() == commandName;
}

protected static bool ParseCommandDotName(string commandName, INamedValueTokens tokens, ICommandValues values, bool requireCommandValues = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private static bool DoDisplayHelpTopic(INamedValues values)
private static bool DisplayHelp(string path, INamedValues values)
{
var interactive = values.GetOrDefault("x.help.interactive", true) &&
values.GetCommand() == "help" &&
values.GetCommandOrEmpty() == "help" &&
!Console.IsInputRedirected &&
!Console.IsOutputRedirected;

Expand Down
Loading