public void ShouldAssignArgsToArgsProperty() { var args = new[] { "arg1", "arg2" }; var settings = CommandLineReader.Parse <ArgsSetting>(args); Assert.Equal(new[] { "arg1", "arg2" }, settings.Args); }
public void ShouldAcceptLinuxPath() { var args = new[] { "--output", "/var/test" }; var settings = CommandLineReader.Parse <LinuxPathSetting>(args); Assert.Equal("/var/test", settings.Output); }
public void ShouldParseVerbWithMultipleParameters() { var args = new[] { "transfer", "user1", "user2" }; var settings = CommandLineReader.Parse <VerbWithMultipleParametersSetting>(args); Assert.Equal(new[] { "user1", "user2" }, settings.Transfer); }
public void ShouldParseVerbWithSingleParameter() { var args = new[] { "new", "project" }; var settings = CommandLineReader.Parse <VerbWithSingleParameterSetting>(args); Assert.Equal("project", settings.New); }
public void ShouldParseSingleVerbAsBoolean() { var args = new[] { "verb", "-param1", "--param2", "/param3" }; var settings = CommandLineReader.Parse <SingleVerbSetting>(args); Assert.True(settings.Verb); Assert.True(settings.Param1); Assert.True(settings.Param2); Assert.True(settings.Param3); }
public MainForm() { Instance = this; InitializeComponent(); // Set the XML file's build action to "Embedded Resource" and "Never copy" for this to work. Tx.LoadFromEmbeddedResource("Unclassified.LogSubmit.LogSubmit.txd"); TxDictionaryBinding.AddTextBindings(this); // Initialise views logSelectionView = new LogSelectionView(); // Read configuration file string configFile = Path.Combine( Path.GetDirectoryName(Application.ExecutablePath), "submit.config"); try { ConfigReader config = new ConfigReader(configFile); config.Read(); } catch (Exception ex) { logSelectionView.SetConfigError(ex); } // Initialise more views timeSelectionView = new TimeSelectionView(); notesView = new NotesView(); compressView = new CompressView(); transportView = new TransportView(); transportProgressView = new TransportProgressView(); views.Add(logSelectionView); views.Add(timeSelectionView); views.Add(notesView); views.Add(compressView); views.Add(transportView); views.Add(transportProgressView); // Other initialisation Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); UIPreferences.UpdateFormFont(this, Font, SystemFonts.MessageBoxFont); USizeGrip.AddToForm(this); systemMenu = new SystemMenu(this); systemMenu.AddCommand(Tx.T("menu.about"), OnSysMenuAbout, true); progressPanel = new Panel(); progressPanel.Left = 0; progressPanel.Top = 0; progressPanel.Width = 0; progressPanel.Height = 2; //progressPanel.BackColor = SystemColors.Highlight; progressPanel.BackColor = Color.Gray; Controls.Add(progressPanel); progressPanel.BringToFront(); // Parse command line arguments CommandLineReader cmdLine = new CommandLineReader(); fromErrorDlgOption = cmdLine.RegisterOption("errordlg"); fromShortcutOption = cmdLine.RegisterOption("shortcut"); logPathOption = cmdLine.RegisterOption("logpath", 1); endTimeOption = cmdLine.RegisterOption("endtime", 1); try { cmdLine.Parse(); } catch (Exception ex) { MessageBox.Show( Tx.T("msg.command line error", "msg", ex.Message), Tx.T("msg.title.error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } SharedData.Instance.FromErrorDialog = fromErrorDlgOption.IsSet; SharedData.Instance.FromShortcut = fromShortcutOption.IsSet; if (logPathOption.IsSet) { try { logSelectionView.SetLogBasePath(logPathOption.Value); } catch { MessageBox.Show( Tx.T("msg.logpath parameter invalid", "value", logPathOption.Value), Tx.T("msg.title.error"), MessageBoxButtons.OK, MessageBoxIcon.Error); logSelectionView.ResetLogBasePath(); logSelectionView.FindLogBasePath(); } } else { logSelectionView.FindLogBasePath(); } if (endTimeOption.IsSet) { try { appStartTime = DateTime.Parse(endTimeOption.Value); SharedData.Instance.LastLogUpdateTime = appStartTime; } catch { MessageBox.Show( Tx.T("msg.endtime parameter invalid", "value", endTimeOption.Value), Tx.T("msg.title.error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Set start view SetView(logSelectionView, true); }
public void ShouldThrowWhenMissingRequiredArgumentOnArray() { var args = new[] { "new", "project" }; Assert.Throws <CommandLineParserException>(() => CommandLineReader.Parse <TwoVerbArgumentsArraySetting>(args)); }
public void ShouldThrowWhenMissingRequiredArgumentOnSingleVerb() { var args = new[] { "new" }; Assert.Throws <CommandLineParserException>(() => CommandLineReader.Parse <VerbWithSingleParameterSetting>(args)); }