@@ -28,7 +28,7 @@ public sealed class SaveOnnxCommand : DataCommand.ImplBase<SaveOnnxCommand.Argum
2828
2929 public sealed class Arguments : DataCommand . ArgumentsBase
3030 {
31- [ Argument ( ArgumentType . AtMostOnce , HelpText = "The path to write the output ONNX to." , SortOrder = 1 ) ]
31+ [ Argument ( ArgumentType . Required , HelpText = "The path to write the output ONNX to." , SortOrder = 1 ) ]
3232 public string Onnx ;
3333
3434 [ Argument ( ArgumentType . AtMostOnce , HelpText = "The path to write the output JSON to." , SortOrder = 2 ) ]
@@ -74,13 +74,18 @@ public SaveOnnxCommand(IHostEnvironment env, Arguments args)
7474 : base ( env , args , LoadName )
7575 {
7676 Host . CheckValue ( args , nameof ( args ) ) ;
77+ Host . CheckNonWhiteSpace ( args . Onnx , nameof ( args . Onnx ) ) ;
78+
7779 Utils . CheckOptionalUserDirectory ( args . Onnx , nameof ( args . Onnx ) ) ;
78- _outputModelPath = string . IsNullOrWhiteSpace ( args . Onnx ) ? null : args . Onnx ;
80+ _outputModelPath = args . Onnx ;
7981 _outputJsonModelPath = string . IsNullOrWhiteSpace ( args . Json ) ? null : args . Json ;
80- if ( args . Name == null && _outputModelPath != null )
82+ if ( args . Name == null )
8183 _name = Path . GetFileNameWithoutExtension ( _outputModelPath ) ;
82- else if ( ! string . IsNullOrWhiteSpace ( args . Name ) )
84+ else
85+ {
86+ Host . CheckNonWhiteSpace ( args . Name , nameof ( args . Name ) ) ;
8387 _name = args . Name ;
88+ }
8489
8590 _loadPredictor = args . LoadPredictor ;
8691 _inputsToDrop = CreateDropMap ( args . InputsToDropArray ?? args . InputsToDrop ? . Split ( ',' ) ) ;
@@ -237,12 +242,9 @@ private void Run(IChannel ch)
237242 }
238243
239244 var model = ctx . MakeModel ( ) ;
240- if ( _outputModelPath != null )
241- {
242- using ( var file = Host . CreateOutputFile ( _outputModelPath ) )
243- using ( var stream = file . CreateWriteStream ( ) )
244- model . WriteTo ( stream ) ;
245- }
245+ using ( var file = Host . CreateOutputFile ( _outputModelPath ) )
246+ using ( var stream = file . CreateWriteStream ( ) )
247+ model . WriteTo ( stream ) ;
246248
247249 if ( _outputJsonModelPath != null )
248250 {
0 commit comments