├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── CHANGELOG.md ├── CommandLine.sln ├── CommandLine.snk ├── Directory.Build.props ├── License.md ├── README.md ├── appveyor.yml ├── art ├── CommandLine.png ├── CommandLine20.png ├── CommandLineNuGet.png ├── CommandLinePreRelNuGet.png └── resharper-logo.png ├── demo ├── ReadText.Demo.VB │ ├── App.config │ ├── My Project │ │ ├── Application.Designer.vb │ │ ├── Application.myapp │ │ ├── AssemblyInfo.vb │ │ ├── Resources.Designer.vb │ │ ├── Resources.resx │ │ ├── Settings.Designer.vb │ │ ├── Settings.settings │ │ └── app.manifest │ ├── Options.vb │ ├── Program.vb │ ├── ReadText.Demo.VB.sln │ ├── ReadText.Demo.VB.vbproj │ ├── ReadText.Demo.VB.vbproj.user │ └── packages.config ├── ReadText.Demo │ ├── Options.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReadText.Demo.csproj │ ├── ReadText.Demo.sln │ └── packages.config ├── ReadText.LocalizedDemo │ ├── .cr │ │ └── personal │ │ │ └── Navigation │ │ │ └── RecentFilesHistory.xml │ ├── LocalizableSentenceBuilder.cs │ ├── Options.cs │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.cs.resx │ │ ├── Resources.resx │ │ └── launchSettings.json │ ├── ReadText.LocalizedDemo.csproj │ ├── ReadText.LocalizedDemo.sln │ └── packages.config └── fsharp-demo.fsx ├── docs ├── ChangeLog ├── Contributors ├── INFO ├── PublicAPI.md ├── content │ ├── index.fsx │ └── tutorial.fsx ├── files │ └── img │ │ ├── logo-template.pdn │ │ └── logo.png └── tools │ ├── FSharp.Formatting.svclog │ ├── generate.fsx │ ├── packages.config │ └── templates │ └── template.cshtml ├── src └── CommandLine │ ├── BaseAttribute.cs │ ├── CastExtensions.cs │ ├── CommandLine.csproj │ ├── Core │ ├── ArgumentsExtensions.cs │ ├── GetoptTokenizer.cs │ ├── InstanceBuilder.cs │ ├── InstanceChooser.cs │ ├── KeyValuePairHelper.cs │ ├── NameExtensions.cs │ ├── NameLookup.cs │ ├── OptionMapper.cs │ ├── OptionSpecification.cs │ ├── PartitionExtensions.cs │ ├── PreprocessorGuards.cs │ ├── ReflectionExtensions.cs │ ├── Specification.cs │ ├── SpecificationExtensions.cs │ ├── SpecificationGuards.cs │ ├── SpecificationProperty.cs │ ├── SpecificationPropertyExtensions.cs │ ├── SpecificationPropertyRules.cs │ ├── Token.cs │ ├── TokenPartitioner.cs │ ├── Tokenizer.cs │ ├── TypeConverter.cs │ ├── TypeDescriptor.cs │ ├── TypeLookup.cs │ ├── ValueMapper.cs │ ├── ValueSpecification.cs │ └── Verb.cs │ ├── Error.cs │ ├── ErrorExtensions.cs │ ├── HelpTextExtensions.cs │ ├── Infrastructure │ ├── CSharpx │ │ ├── Either.cs │ │ ├── EnumerableExtensions.cs │ │ └── Maybe.cs │ ├── EnumerableExtensions.cs │ ├── ErrorHandling.cs │ ├── ExceptionExtensions.cs │ ├── FSharpOptionHelper.cs │ ├── LocalizableAttributeProperty.cs │ ├── PopsicleSetter.cs │ ├── ReferenceEqualityComparer.cs │ ├── ReflectionHelper.cs │ ├── StringBuilderExtensions.cs │ └── StringExtensions.cs │ ├── IntrospectionExtensions.cs │ ├── NameInfo.cs │ ├── NullInstance.cs │ ├── OptionAttribute.cs │ ├── Parser.cs │ ├── ParserExtensions.cs │ ├── ParserResult.cs │ ├── ParserResultExtensions.cs │ ├── ParserResultExtensionsAsync.cs │ ├── ParserSettings.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Text │ ├── AssemblyLicenseAttribute.cs │ ├── AssemblyUsageAttribute.cs │ ├── CopyrightInfo.cs │ ├── Example.cs │ ├── HeadingInfo.cs │ ├── HelpText.cs │ ├── MultiLineTextAttribute.cs │ ├── SentenceBuilder.cs │ ├── TextWrapper.cs │ └── UsageAttribute.cs │ ├── UnParserExtensions.cs │ ├── ValueAttribute.cs │ └── VerbAttribute.cs └── tests └── CommandLine.Tests ├── CommandLine.Tests.csproj ├── CultureInfoExtensions.cs ├── Fakes ├── CustomAttribute.cs ├── Custom_Struct.cs ├── HelpTextWithLineBreaksAndSubIndentation_Options.cs ├── HelpTextWithLineBreaks_Options.cs ├── HelpTextWithMixedLineBreaks_Options.cs ├── Help_Fakes.cs ├── Hidden_Option.cs ├── IInterface_With_Two_Scalar_Options.cs ├── Immutable_Simple_Options.cs ├── Immutable_Verb_Fakes.cs ├── Mutable_Without_Empty_Constructor.cs ├── Options_HelpText_Ordering.cs ├── Options_With_Both_Min_And_Max_Set_To_Zero.cs ├── Options_With_Custom_Help_Option.cs ├── Options_With_Custom_Version_Option.cs ├── Options_With_Default_Set_To_Sequence.cs ├── Options_With_Defaults.cs ├── Options_With_Enum_Having_HelpText.cs ├── Options_With_FSharpOption.cs ├── Options_With_FileDirectoryInfo.cs ├── Options_With_FlagCounter_Switches.cs ├── Options_With_Group.cs ├── Options_With_Guid.cs ├── Options_With_HelpText_And_MetaValue.cs ├── Options_With_Interface.cs ├── Options_With_InvalidDefaults.cs ├── Options_With_Max_Set_To_Zero.cs ├── Options_With_MetaValue.cs ├── Options_With_Min_Set_To_Zero.cs ├── Options_With_Multiple_Groups.cs ├── Options_With_Named_And_Empty_Sets.cs ├── Options_With_Nullable_Enum_Having_HelpText.cs ├── Options_With_Nullables.cs ├── Options_With_Only_Explicit_Interface.cs ├── Options_With_Option_And_Value_Of_String_Type.cs ├── Options_With_Option_Sequence_And_Value_Sequence.cs ├── Options_With_Property_Throwing_Exception.cs ├── Options_With_Required_Set_To_True.cs ├── Options_With_Required_Set_To_True_For_Values.cs ├── Options_With_Required_Set_To_True_Within_Same_Set.cs ├── Options_With_Scalar_Value_And_Adjacent_SequenceString.cs ├── Options_With_Sequence.cs ├── Options_With_Sequence_And_Only_Max_Constraint.cs ├── Options_With_Sequence_And_Only_Max_Constraint_For_Value.cs ├── Options_With_Sequence_And_Only_Min_Constraint.cs ├── Options_With_Sequence_And_Only_Min_Constraint_For_Value.cs ├── Options_With_Sequence_Having_Both_Min_And_Max_Equal.cs ├── Options_With_Sequence_Having_Separator_And_Values.cs ├── Options_With_Sequence_Having_Separator_Set.cs ├── Options_With_Sequence_Without_Range_For_Value.cs ├── Options_With_SetName_That_Ends_With_Previous_SetName.cs ├── Options_With_Shuffled_Index_Values.cs ├── Options_With_Similar_Names.cs ├── Options_With_Switches.cs ├── Options_With_TimeSpan.cs ├── Options_With_Two_Option_Required_Set_To_True_And_Two_Sets.cs ├── Options_With_Two_Options_Having_Required_Set_To_True.cs ├── Options_With_Two_Sets.cs ├── Options_With_Uri_And_SimpleType.cs ├── Options_With_Value_Sequence_And_Normal_Option.cs ├── ResourceFakes.cs ├── Simple_Options.cs ├── Simple_Options_With_Double_Value.cs ├── Simple_Options_With_Enum.cs ├── Simple_Options_With_ExtraArgs.cs ├── Simple_Options_With_Multiple_OptionGroups.cs ├── Simple_Options_With_OptionGroup.cs ├── Simple_Options_With_OptionGroup_MutuallyExclusiveSet.cs ├── Simple_Options_With_OptionGroup_WithDefaultValue.cs ├── Simple_Options_With_OptionGroup_WithOptionDefaultValue.cs ├── Simple_Options_With_Required_OptionGroup.cs ├── Simple_Options_With_Values.cs └── Verb_Fakes.cs ├── StringExtensions.cs └── Unit ├── BaseAttributeTests.cs ├── Core ├── GetoptTokenizerTests.cs ├── InstanceBuilderTests.cs ├── InstanceChooserTests.cs ├── KeyValuePairHelperTests.cs ├── NameLookupTests.cs ├── OptionMapperTests.cs ├── ReflectionExtensions.cs ├── ScalarTests.cs ├── SequenceTests.cs ├── SpecificationPropertyRulesTests.cs ├── SwitchTests.cs ├── TextWrapperTests.cs ├── TokenPartitionerTests.cs ├── TokenTests.cs ├── TokenizerTests.cs └── TypeConverterTests.cs ├── GetoptParserTests.cs ├── Infrastructure └── FSharpOptionHelperTests.cs ├── Issue104Tests.cs ├── Issue389Tests.cs ├── Issue418Tests.cs ├── Issue424Tests.cs ├── Issue482Tests.cs ├── Issue543Tests.cs ├── Issue591Tests.cs ├── Issue6Tests.cs ├── Issue70Tests.cs ├── Issue776Tests.cs ├── ParserResultExtensionsTests.cs ├── ParserSettingsTests.cs ├── ParserTests.cs ├── SequenceParsingTests.cs ├── StringBuilderExtensionsTests.cs ├── Text ├── HelpTextAutoBuildFix.cs └── HelpTextTests.cs ├── UnParserExtensionsTests.cs └── VerbAttributeTests.cs /.editorconfig: -------------------------------------------------------------------------------- 1 | #top-most EditorConfig for project 2 | root = true 3 | 4 | [*] 5 | end_of_line = crlf 6 | insert_final_newline = true 7 | 8 | [*.cs] 9 | indent_style = space 10 | indent_size = 4 11 | 12 | [*.{xml,csproj,config}] 13 | indent_style = tab 14 | indent_size = 4 15 | 16 | [*.json] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.js] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | [*.yml] 25 | indent_style = space 26 | indent_size = 2 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Either fork from this fiddle and paste link here: https://dotnetfiddle.net/mh9CjX 15 | 16 | or 17 | 18 | Steps to reproduce the behavior: 19 | 1. Go to '...' 20 | 2. Click on '....' 21 | 3. Scroll down to '....' 22 | 4. See error 23 | 24 | **Expected behavior** 25 | A clear and concise description of what you expected to happen. 26 | 27 | **Screenshots** 28 | If applicable, add screenshots to help explain your problem. 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore build outputs 3 | [B|b]in 4 | [O|o]bj 5 | build/* 6 | 7 | #ignore managed external libs 8 | packages 9 | paket-files 10 | 11 | *.suo 12 | *.userprefs 13 | *~ 14 | \#*\# 15 | *.pidb 16 | 17 | #ignore Test results/temps 18 | *.test-cache 19 | tests/CommandLine/test-results/* 20 | tests/CommandLine.Tests/test-results/* 21 | TestResult.xml 22 | 23 | *.DS_Store 24 | *.csproj.user 25 | *.nupkg 26 | *.old 27 | StyleCop.Cache 28 | .paket/paket.exe 29 | .fake 30 | *.cache 31 | docs/output/* 32 | artifacts/* 33 | *.xproj.user 34 | *.nuget.targets 35 | *.lock.json 36 | *.nuget.props 37 | *.DotSettings.user 38 | # Visual Studio 2015 cache/options directory 39 | .vs/ 40 | # Rider 41 | .idea/ 42 | 43 | [R|r]elease/** 44 | -------------------------------------------------------------------------------- /CommandLine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2042 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine", "src\CommandLine\CommandLine.csproj", "{E1BD3C65-49C3-49E7-BABA-C60980CB3F20}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine.Tests", "tests\CommandLine.Tests\CommandLine.Tests.csproj", "{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{1361E8B1-D0E1-493E-B8C1-7380A7B7C472}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E1BD3C65-49C3-49E7-BABA-C60980CB3F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {E1BD3C65-49C3-49E7-BABA-C60980CB3F20}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {E1BD3C65-49C3-49E7-BABA-C60980CB3F20}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {E1BD3C65-49C3-49E7-BABA-C60980CB3F20}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(NestedProjects) = preSolution 31 | {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E} = {1361E8B1-D0E1-493E-B8C1-7380A7B7C472} 32 | EndGlobalSection 33 | GlobalSection(ExtensibilityGlobals) = postSolution 34 | SolutionGuid = {5B5A476C-82FB-49FB-B592-5224D9005186} 35 | EndGlobalSection 36 | GlobalSection(MonoDevelopProperties) = preSolution 37 | StartupItem = src\CommandLine\CommandLine.csproj 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /CommandLine.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/CommandLine.snk -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | CS1591;CS0219;8002;NU5125 4 | $(MSBuildThisFileDirectory) 5 | false 6 | 7 | 8 | $(DefineConstants);NETFRAMEWORK 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers 14 | all 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2005 - 2015 Giacomo Stelluti Scala & Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | #version should be only changed with RELEASE eminent, see RELEASE.md 2 | 3 | version: 2.9.1-ci-{build} 4 | 5 | image: Visual Studio 2019 6 | 7 | clone_depth: 1 8 | pull_requests: 9 | do_not_increment_build_number: true 10 | 11 | init: 12 | - ps: | 13 | git config --global core.autocrlf input 14 | 15 | if ($env:APPVEYOR_REPO_TAG -eq "true") { 16 | $ver = $env:APPVEYOR_REPO_TAG_NAME 17 | if($ver.StartsWith("v") -eq $true) { $ver = $ver.Substring(1) } 18 | Update-AppveyorBuild -Version $ver 19 | } 20 | 21 | environment: 22 | matrix: 23 | - BUILD_TARGET: base 24 | - BUILD_TARGET: fsharp 25 | 26 | build_script: 27 | - cmd: dotnet build src/CommandLine/ -c Release --version-suffix %APPVEYOR_BUILD_VERSION% /p:BuildTarget=%BUILD_TARGET% 28 | 29 | test_script: 30 | - cmd: dotnet test tests/CommandLine.Tests/ /p:BuildTarget=%BUILD_TARGET% 31 | 32 | after_test: 33 | - cmd: dotnet pack src/CommandLine/ -c Release --version-suffix %APPVEYOR_BUILD_VERSION% /p:BuildTarget=%BUILD_TARGET% 34 | 35 | artifacts: 36 | - path: 'src/CommandLine/bin/Release/*.nupkg' 37 | name: NuGetPackages 38 | - path: 'src/CommandLine/bin/Release/*.snupkg' 39 | name: symbol 40 | 41 | on_failure: 42 | - cmd: | 43 | tree /f /a >files.lst 44 | appveyor PushArtifact .\files.lst -DeploymentName "Failed Build File Listing" 45 | 46 | deploy: 47 | - provider: NuGet 48 | api_key: 49 | secure: llMIgYMuLHh9thyKMEAmkWraTaA9Zvcm1F8/yRwm0HCiPIt/ehR/GI4kJKyMTPyf 50 | artifact: /.*(\.|\.s)nupkg/ 51 | on: 52 | APPVEYOR_REPO_TAG: true 53 | -------------------------------------------------------------------------------- /art/CommandLine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/art/CommandLine.png -------------------------------------------------------------------------------- /art/CommandLine20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/art/CommandLine20.png -------------------------------------------------------------------------------- /art/CommandLineNuGet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/art/CommandLineNuGet.png -------------------------------------------------------------------------------- /art/CommandLinePreRelNuGet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/art/CommandLinePreRelNuGet.png -------------------------------------------------------------------------------- /art/resharper-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/commandlineparser/commandline/1e3607b97af6141743edb3c434c06d5b492f6fb3/art/resharper-logo.png -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.42000 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 2 9 | true 10 | 11 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/Resources.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.42000 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | Imports System 15 | 16 | Namespace My.Resources 17 | 18 | 'This class was auto-generated by the StronglyTypedResourceBuilder 19 | 'class via a tool like ResGen or Visual Studio. 20 | 'To add or remove a member, edit your .ResX file then rerun ResGen 21 | 'with the /str option, or rebuild your VS project. 22 | ''' 23 | ''' A strongly-typed resource class, for looking up localized strings, etc. 24 | ''' 25 | _ 29 | Friend Module Resources 30 | 31 | Private resourceMan As Global.System.Resources.ResourceManager 32 | 33 | Private resourceCulture As Global.System.Globalization.CultureInfo 34 | 35 | ''' 36 | ''' Returns the cached ResourceManager instance used by this class. 37 | ''' 38 | _ 39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 40 | Get 41 | If Object.ReferenceEquals(resourceMan, Nothing) Then 42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("ReadText.Demo.VB.Resources", GetType(Resources).Assembly) 43 | resourceMan = temp 44 | End If 45 | Return resourceMan 46 | End Get 47 | End Property 48 | 49 | ''' 50 | ''' Overrides the current thread's CurrentUICulture property for all 51 | ''' resource lookups using this strongly typed resource class. 52 | ''' 53 | _ 54 | Friend Property Culture() As Global.System.Globalization.CultureInfo 55 | Get 56 | Return resourceCulture 57 | End Get 58 | Set 59 | resourceCulture = value 60 | End Set 61 | End Property 62 | End Module 63 | End Namespace 64 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/Settings.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.42000 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.ReadText.Demo.VB.My.MySettings 68 | Get 69 | Return Global.ReadText.Demo.VB.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/My Project/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 59 | 60 | 61 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/Options.vb: -------------------------------------------------------------------------------- 1 | Imports CommandLine 2 | Imports CommandLine.Text 3 | 4 | Public Interface IOptions 5 | 6 | <[Option]("n"c, "lines", SetName:="bylines", [Default]:=5UI, HelpText:="Lines to be printed from the beginning or end of the file.")> 7 | Property Lines As UInteger? 8 | 9 | <[Option]("c"c, "bytes", SetName:="bybytes", HelpText:="Bytes to be printed from the beginning or end of the file.")> 10 | Property Bytes As UInteger? 11 | 12 | <[Option]("q"c, "quiet", HelpText:="Suppresses summary messages.")> 13 | Property Quiet As Boolean 14 | 15 | <[Value](0, MetaName:="input file", Required:=True, HelpText:="Input file to be processed.")> 16 | Property FileName As String 17 | 18 | End Interface 19 | 20 | <[Verb]("head", HelpText:="Displays first lines of a file.")> 21 | Public Class HeadOptions 22 | Implements IOptions 23 | Public Property Lines As UInteger? Implements IOptions.Lines 24 | 25 | Public Property Bytes As UInteger? Implements IOptions.Bytes 26 | 27 | Public Property Quiet As Boolean Implements IOptions.Quiet 28 | 29 | Public Property FileName As String Implements IOptions.FileName 30 | 31 | 32 | Public Shared ReadOnly Iterator Property IEnumerable() As IEnumerable(Of Example) 33 | Get 34 | Yield New Example("normal scenario", New HeadOptions With {.FileName = "file.bin"}) 35 | Yield New Example("specify bytes", New HeadOptions With {.FileName = "file.bin", .Bytes = 100}) 36 | Yield New Example("suppress summary", UnParserSettings.WithGroupSwitchesOnly(), New HeadOptions With {.FileName = "file.bin", .Quiet = True}) 37 | Yield New Example("read more lines", New UnParserSettings() {UnParserSettings.WithGroupSwitchesOnly(), UnParserSettings.WithUseEqualTokenOnly()}, New HeadOptions With {.FileName = "file.bin", .Lines = 10}) 38 | End Get 39 | End Property 40 | 41 | End Class 42 | 43 | <[Verb]("tail", HelpText:="Displays last lines of a file.")> 44 | Public Class TailOptions 45 | Implements IOptions 46 | Public Property Lines As UInteger? Implements IOptions.Lines 47 | 48 | Public Property Bytes As UInteger? Implements IOptions.Bytes 49 | 50 | Public Property Quiet As Boolean Implements IOptions.Quiet 51 | 52 | Public Property FileName As String Implements IOptions.FileName 53 | 54 | End Class 55 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/Program.vb: -------------------------------------------------------------------------------- 1 | Imports System.IO 2 | Imports System.Text 3 | Imports CommandLine 4 | 5 | Module Program 6 | 7 | Function Main(ByVal sArgs() As String) As Integer 8 | 9 | Dim reader As Func(Of IOptions, String) = Function(opts) 10 | Dim fromTop = opts.[GetType]() = GetType(HeadOptions) 11 | Return If(opts.Lines.HasValue, ReadLines(opts.FileName, fromTop, CInt(opts.Lines)), ReadBytes(opts.FileName, fromTop, CInt(opts.Bytes))) 12 | End Function 13 | 14 | Dim header As Func(Of IOptions, String) = Function(opts) 15 | If opts.Quiet Then Return String.Empty 16 | 17 | Dim fromTop = opts.[GetType]() = GetType(HeadOptions) 18 | Dim builder = New StringBuilder("Reading ") 19 | builder = If(opts.Lines.HasValue, builder.Append(opts.Lines).Append(" lines"), builder.Append(opts.Bytes).Append(" bytes")) 20 | builder = If(fromTop, builder.Append(" from top:"), builder.Append(" from bottom:")) 21 | Return builder.ToString() 22 | 23 | End Function 24 | 25 | Dim printIfNotEmpty As Action(Of String) = Sub(text) 26 | If text.Length = 0 Then Return 27 | Console.WriteLine(text) 28 | End Sub 29 | 30 | Dim result = Parser.Default.ParseArguments(Of HeadOptions, TailOptions)(sArgs) 31 | 32 | Dim texts = result.MapResult( 33 | Function(opts As HeadOptions) Tuple.Create(header(opts), reader(opts)), 34 | Function(opts As TailOptions) Tuple.Create(header(opts), reader(opts)), 35 | Function() MakeError()) 36 | 37 | printIfNotEmpty(texts.Item1) 38 | printIfNotEmpty(texts.Item2) 39 | 40 | Return If(texts.Equals(MakeError()), 1, 0) 41 | 42 | End Function 43 | 44 | Private Function ReadLines(fileName As String, fromTop As Boolean, count As Integer) As String 45 | 46 | Dim lines = File.ReadAllLines(fileName) 47 | If (fromTop) Then 48 | Return String.Join(Environment.NewLine, lines.Take(count)) 49 | End If 50 | 51 | Return String.Join(Environment.NewLine, lines.Reverse().Take(count)) 52 | 53 | End Function 54 | 55 | Private Function ReadBytes(fileName As String, fromTop As Boolean, count As Integer) As String 56 | 57 | Dim bytes = File.ReadAllBytes(fileName) 58 | If (fromTop) Then 59 | Return Encoding.UTF8.GetString(bytes, 0, count) 60 | End If 61 | 62 | Return Encoding.UTF8.GetString(bytes, bytes.Length - count, count) 63 | 64 | End Function 65 | 66 | Private Function MakeError() As Tuple(Of String, String) 67 | 68 | Return Tuple.Create(vbNullChar, vbNullChar) 69 | 70 | End Function 71 | 72 | End Module 73 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/ReadText.Demo.VB.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ReadText.Demo.VB", "ReadText.Demo.VB.vbproj", "{298FBAFF-C828-4BF9-8E93-2BE925E9E223}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | publish\ 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | -------------------------------------------------------------------------------- /demo/ReadText.Demo.VB/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/Options.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using CommandLine.Text; 3 | using System.Collections.Generic; 4 | 5 | namespace ReadText.Demo 6 | { 7 | interface IOptions 8 | { 9 | [Option('n', "lines", 10 | Default = 5U, 11 | SetName = "bylines", 12 | HelpText = "Lines to be printed from the beginning or end of the file.")] 13 | uint? Lines { get; set; } 14 | 15 | [Option('c', "bytes", 16 | SetName = "bybytes", 17 | HelpText = "Bytes to be printed from the beginning or end of the file.")] 18 | uint? Bytes { get; set; } 19 | 20 | [Option('q', "quiet", 21 | HelpText = "Suppresses summary messages.")] 22 | bool Quiet { get; set; } 23 | 24 | [Value(0, MetaName = "input file", 25 | HelpText = "Input file to be processed.", 26 | Required = true)] 27 | string FileName { get; set; } 28 | } 29 | 30 | [Verb("head", true, HelpText = "Displays first lines of a file.")] 31 | class HeadOptions : IOptions 32 | { 33 | public uint? Lines { get; set; } 34 | 35 | public uint? Bytes { get; set; } 36 | 37 | public bool Quiet { get; set; } 38 | 39 | public string FileName { get; set; } 40 | 41 | [Usage(ApplicationAlias = "ReadText.Demo.exe")] 42 | public static IEnumerable Examples 43 | { 44 | get 45 | { 46 | yield return new Example("normal scenario", new HeadOptions { FileName = "file.bin"}); 47 | yield return new Example("specify bytes", new HeadOptions { FileName = "file.bin", Bytes=100 }); 48 | yield return new Example("suppress summary", UnParserSettings.WithGroupSwitchesOnly(), new HeadOptions { FileName = "file.bin", Quiet = true }); 49 | yield return new Example("read more lines", new[] { UnParserSettings.WithGroupSwitchesOnly(), UnParserSettings.WithUseEqualTokenOnly() }, new HeadOptions { FileName = "file.bin", Lines = 10 }); 50 | } 51 | } 52 | } 53 | 54 | [Verb("tail", HelpText = "Displays last lines of a file.")] 55 | class TailOptions : IOptions 56 | { 57 | public uint? Lines { get; set; } 58 | 59 | public uint? Bytes { get; set; } 60 | 61 | public bool Quiet { get; set; } 62 | 63 | public string FileName { get; set; } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using CommandLine; 7 | using CommandLine.Text; 8 | 9 | namespace ReadText.Demo 10 | { 11 | class Program 12 | { 13 | public static int Main(string[] args) 14 | { 15 | Func reader = opts => 16 | { 17 | var fromTop = opts.GetType() == typeof(HeadOptions); 18 | return opts.Lines.HasValue 19 | ? ReadLines(opts.FileName, fromTop, (int)opts.Lines) 20 | : ReadBytes(opts.FileName, fromTop, (int)opts.Bytes); 21 | }; 22 | Func header = opts => 23 | { 24 | if (opts.Quiet) 25 | { 26 | return string.Empty; 27 | } 28 | var fromTop = opts.GetType() == typeof(HeadOptions); 29 | var builder = new StringBuilder("Reading "); 30 | builder = opts.Lines.HasValue 31 | ? builder.Append(opts.Lines).Append(" lines") 32 | : builder.Append(opts.Bytes).Append(" bytes"); 33 | builder = fromTop ? builder.Append(" from top:") : builder.Append(" from bottom:"); 34 | return builder.ToString(); 35 | }; 36 | Action printIfNotEmpty = text => 37 | { 38 | if (text.Length == 0) { return; } 39 | Console.WriteLine(text); 40 | }; 41 | 42 | var result = Parser.Default.ParseArguments(args); 43 | var texts = result 44 | .MapResult( 45 | (HeadOptions opts) => Tuple.Create(header(opts), reader(opts)), 46 | (TailOptions opts) => Tuple.Create(header(opts), reader(opts)), 47 | _ => MakeError()); 48 | 49 | printIfNotEmpty(texts.Item1); 50 | printIfNotEmpty(texts.Item2); 51 | 52 | return texts.Equals(MakeError()) ? 1 : 0; 53 | } 54 | 55 | private static string ReadLines(string fileName, bool fromTop, int count) 56 | { 57 | var lines = File.ReadAllLines(fileName); 58 | if (fromTop) 59 | { 60 | return string.Join(Environment.NewLine, lines.Take(count)); 61 | } 62 | return string.Join(Environment.NewLine, lines.Reverse().Take(count)); 63 | } 64 | 65 | private static string ReadBytes(string fileName, bool fromTop, int count) 66 | { 67 | var bytes = File.ReadAllBytes(fileName); 68 | if (fromTop) 69 | { 70 | return Encoding.UTF8.GetString(bytes, 0, count); 71 | } 72 | return Encoding.UTF8.GetString(bytes, bytes.Length - count, count); 73 | } 74 | 75 | private static Tuple MakeError() 76 | { 77 | return Tuple.Create("\0", "\0"); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyTitle("ReadText.Demo")] 5 | [assembly: AssemblyDescription("ReadText.Demo for Command Line Parser Library")] 6 | [assembly: AssemblyTrademark("")] 7 | #if DEBUG 8 | [assembly: AssemblyConfiguration("Debug")] 9 | #else 10 | [assembly: AssemblyConfiguration("Release")] 11 | #endif 12 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/ReadText.Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | net40;net45;net461;netcoreapp2.1;netcoreapp2.0 5 | false 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/ReadText.Demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.106 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReadText.Demo", "ReadText.Demo.csproj", "{F9D3B288-1A73-4C91-8ED7-11ED1704B817}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine", "..\..\src\CommandLine\CommandLine.csproj", "{A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FF14CDF0-EF51-448B-918C-47CD369568DF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /demo/ReadText.Demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/.cr/personal/Navigation/RecentFilesHistory.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | LocalizableAttributeProperty.cs 7 | d:\work\arci\commandline\src\commandline\infrastructure\localizableattributeproperty.cs 8 | 9 | Infrastructure 10 | 11 | d:\WORK\ARCI\commandline\src\CommandLine\CommandLine.csproj 12 | CommandLine 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/Options.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using CommandLine.Text; 3 | using System.Collections.Generic; 4 | 5 | namespace ReadText.LocalizedDemo 6 | { 7 | interface IOptions 8 | { 9 | [Option('n', "lines", 10 | Default = 5U, 11 | SetName = "bylines", 12 | HelpText = "HelpTextLines", 13 | ResourceType = typeof(Properties.Resources))] 14 | uint? Lines { get; set; } 15 | 16 | [Option('c', "bytes", 17 | SetName = "bybytes", 18 | HelpText = "HelpTextBytes", 19 | ResourceType = typeof(Properties.Resources))] 20 | uint? Bytes { get; set; } 21 | 22 | [Option('q', "quiet", 23 | HelpText = "HelpTextQuiet", 24 | ResourceType = typeof(Properties.Resources))] 25 | bool Quiet { get; set; } 26 | 27 | [Value(0, MetaName = "input file", 28 | HelpText = "HelpTextFileName", 29 | Required = true, 30 | ResourceType = typeof(Properties.Resources))] 31 | string FileName { get; set; } 32 | } 33 | 34 | [Verb("head", HelpText = "HelpTextVerbHead", ResourceType = typeof(Properties.Resources))] 35 | class HeadOptions : IOptions 36 | { 37 | public uint? Lines { get; set; } 38 | 39 | public uint? Bytes { get; set; } 40 | 41 | public bool Quiet { get; set; } 42 | 43 | public string FileName { get; set; } 44 | 45 | [Usage(ApplicationAlias = "ReadText.LocalizedDemo.exe")] 46 | public static IEnumerable Examples 47 | { 48 | get 49 | { 50 | yield return new Example(Properties.Resources.ExamplesNormalScenario, new HeadOptions { FileName = "file.bin"}); 51 | yield return new Example(Properties.Resources.ExamplesSpecifyBytes, new HeadOptions { FileName = "file.bin", Bytes=100 }); 52 | yield return new Example(Properties.Resources.ExamplesSuppressSummary, UnParserSettings.WithGroupSwitchesOnly(), new HeadOptions { FileName = "file.bin", Quiet = true }); 53 | yield return new Example(Properties.Resources.ExamplesReadMoreLines, new[] { UnParserSettings.WithGroupSwitchesOnly(), UnParserSettings.WithUseEqualTokenOnly() }, new HeadOptions { FileName = "file.bin", Lines = 10 }); 54 | } 55 | } 56 | } 57 | 58 | [Verb("tail", HelpText = "HelpTextVerbTail", ResourceType = typeof(Properties.Resources))] 59 | class TailOptions : IOptions 60 | { 61 | public uint? Lines { get; set; } 62 | 63 | public uint? Bytes { get; set; } 64 | 65 | public bool Quiet { get; set; } 66 | 67 | public string FileName { get; set; } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using CommandLine; 7 | using CommandLine.Text; 8 | 9 | namespace ReadText.LocalizedDemo 10 | { 11 | class Program 12 | { 13 | public static int Main(string[] args) 14 | { 15 | // Set sentence builder to localizable 16 | SentenceBuilder.Factory = () => new LocalizableSentenceBuilder(); 17 | 18 | Func reader = opts => 19 | { 20 | var fromTop = opts.GetType() == typeof(HeadOptions); 21 | return opts.Lines.HasValue 22 | ? ReadLines(opts.FileName, fromTop, (int)opts.Lines) 23 | : ReadBytes(opts.FileName, fromTop, (int)opts.Bytes); 24 | }; 25 | Func header = opts => 26 | { 27 | if (opts.Quiet) 28 | { 29 | return string.Empty; 30 | } 31 | var fromTop = opts.GetType() == typeof(HeadOptions); 32 | var builder = new StringBuilder(Properties.Resources.Reading); 33 | builder = opts.Lines.HasValue 34 | ? builder.Append(opts.Lines).Append(Properties.Resources.Lines) 35 | : builder.Append(opts.Bytes).Append(Properties.Resources.Bytes); 36 | builder = fromTop ? builder.Append(Properties.Resources.FromTop) : builder.Append(Properties.Resources.FromBottom); 37 | return builder.ToString(); 38 | }; 39 | Action printIfNotEmpty = text => 40 | { 41 | if (text.Length == 0) { return; } 42 | Console.WriteLine(text); 43 | }; 44 | 45 | var result = Parser.Default.ParseArguments(args); 46 | var texts = result 47 | .MapResult( 48 | (HeadOptions opts) => Tuple.Create(header(opts), reader(opts)), 49 | (TailOptions opts) => Tuple.Create(header(opts), reader(opts)), 50 | _ => MakeError()); 51 | 52 | printIfNotEmpty(texts.Item1); 53 | printIfNotEmpty(texts.Item2); 54 | 55 | return texts.Equals(MakeError()) ? 1 : 0; 56 | } 57 | 58 | private static string ReadLines(string fileName, bool fromTop, int count) 59 | { 60 | var lines = File.ReadAllLines(fileName); 61 | if (fromTop) 62 | { 63 | return string.Join(Environment.NewLine, lines.Take(count)); 64 | } 65 | return string.Join(Environment.NewLine, lines.Reverse().Take(count)); 66 | } 67 | 68 | private static string ReadBytes(string fileName, bool fromTop, int count) 69 | { 70 | var bytes = File.ReadAllBytes(fileName); 71 | if (fromTop) 72 | { 73 | return Encoding.UTF8.GetString(bytes, 0, count); 74 | } 75 | return Encoding.UTF8.GetString(bytes, bytes.Length - count, count); 76 | } 77 | 78 | private static Tuple MakeError() 79 | { 80 | return Tuple.Create("\0", "\0"); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyTitle("ReadText.Demo")] 5 | [assembly: AssemblyDescription("ReadText.Demo for Command Line Parser Library")] 6 | [assembly: AssemblyTrademark("")] 7 | #if DEBUG 8 | [assembly: AssemblyConfiguration("Debug")] 9 | #else 10 | [assembly: AssemblyConfiguration("Release")] 11 | #endif 12 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "ReadText.LocalizedDemo": { 4 | "commandName": "Project", 5 | "commandLineArgs": "head" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/ReadText.LocalizedDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | net40;net45;net461;netcoreapp2.1;netcoreapp2.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | True 13 | True 14 | Resources.resx 15 | 16 | 17 | 18 | 19 | PublicResXFileCodeGenerator 20 | Resources.Designer.cs 21 | 22 | 23 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/ReadText.LocalizedDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.106 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReadText.LocalizedDemo", "ReadText.LocalizedDemo.csproj", "{F9D3B288-1A73-4C91-8ED7-11ED1704B817}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine", "..\..\src\CommandLine\CommandLine.csproj", "{A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FF14CDF0-EF51-448B-918C-47CD369568DF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /demo/ReadText.LocalizedDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/fsharp-demo.fsx: -------------------------------------------------------------------------------- 1 | #r "./../src/CommandLine/bin/Debug/CommandLine.dll" 2 | 3 | open CommandLine 4 | open CommandLine.Text 5 | 6 | type options = { 7 | [] stringValue : string; 8 | [] intSequence : int seq; 9 | [] boolValue : bool; 10 | [] longValue : int64 option; } 11 | with 12 | [] 13 | static member examples 14 | with get() = seq { 15 | yield Example("Supply some values", {stringValue = "hello"; boolValue = true; intSequence = seq {1..3}; longValue = Some 10L }) } 16 | 17 | let formatLong o = 18 | match o with 19 | | Some(v) -> string v 20 | | _ -> "{None}" 21 | 22 | let formatInput (o : options) = 23 | sprintf "--stringvalue: %s\n-i: %A\n-x: %b\nvalue: %s\n" o.stringValue o.intSequence o.boolValue (formatLong o.longValue) 24 | 25 | let inline (|Success|Help|Version|Fail|) (result : ParserResult<'a>) = 26 | match result with 27 | | :? Parsed<'a> as parsed -> Success(parsed.Value) 28 | | :? NotParsed<'a> as notParsed when notParsed.Errors.IsHelp() -> Help 29 | | :? NotParsed<'a> as notParsed when notParsed.Errors.IsVersion() -> Version 30 | | :? NotParsed<'a> as notParsed -> Fail(notParsed.Errors) 31 | | _ -> failwith "invalid parser result" 32 | 33 | let args = fsi.CommandLineArgs.[1..] 34 | let result = Parser.Default.ParseArguments(args) 35 | 36 | match result with 37 | | Success(opts) -> printf "%s" (formatInput opts) 38 | | Fail(errs) -> printf "Invalid: %A, Errors: %u\n" args (Seq.length errs) 39 | | Help | Version -> () 40 | -------------------------------------------------------------------------------- /docs/Contributors: -------------------------------------------------------------------------------- 1 | Contributions Guidelines for Command Line Parser Library 2 | Giacomo Stelluti Scala (gsscoder@gmail.com) 3 | Last Mod.: 2013-04-26 4 | 5 | Tools: 6 | - MS FxCop (VSSTUDIO CodeAnalysis) 7 | - MS StyleCop 8 | - JetBrains R# 9 | 10 | Premise 11 | These are suggestions don't be stuck to send pull requests just because you think that something written here is not perfectly followed. 12 | It is possible (or better is almost certain) that also the writer of this document violates some rule... but he tries to adhere! 13 | The project tree includes also two ReSharper files that I try to keep in sync with StyleCop. 14 | 15 | Code Formatting 16 | - No tabs (\t), use for 4 spaces instead. 17 | - Don't overuse spaces: 18 | void Method(param1, param2, param3) -> OK 19 | void Method ( param1, param2, param3 ) -> TOO SPACES! 20 | - Align with one indentation: 21 | if (lonlongstuff1 == longlongstuff2 || (longlongstuff3 > 0 && 22 | longlongstuff4 < 0)) -> OK 23 | if (lonlongstuff1 == longlongstuff2 || (longlongstuff3 > 0 && 24 | longlongstuff4 < 0)) -> TOO INDENTATION! 25 | 26 | Coding Style 27 | - Adhere to .NET Framework Coding Guidelines (http://msdn.microsoft.com/en-us/library/ms229042.aspx) for public types. 28 | - Kernel of 2.0+ has been rewritten following Functional Programming principles (http://en.wikipedia.org/wiki/Functional_programming). 29 | - A minor use of side-effects could be allowed if isolated to "out-side" world (e.g.: see Tokenizer type). 30 | 31 | Unit Tests 32 | Personally 99% of times I write the unit tests before the desidered modification (TDD). Anyway please submit changes along with at least one unit test (this is also useful to let me understand what the change impacts). 33 | 34 | PR etiquette 35 | A not discussed PULL REQUEST could lead only to extra work for project coordinator; 36 | PR are well accepted, anyway they should be result of new or open discussions. 37 | 38 | Breaking Changes 39 | Please discuss any important modification or something that breaks the Public API. 40 | 41 | Not covered here 42 | You can take existing code as a model or write me. 43 | -------------------------------------------------------------------------------- /docs/INFO: -------------------------------------------------------------------------------- 1 | Command Line Parser Library 2 | ------------------------------------------------------------------------------------------- 3 | Project Author/Coordinator: Giacomo Stelluti Scala 4 | Main Contributors: Steven Evans, Kevin Moore, Dan Nemec (nemec), Alexander Fast (mizipzor) 5 | Others: Tom Glastonbury (tg73) 6 | ------------------------------------------------------------------------------------------- 7 | 8 | 9 | Git home: 10 | https://github.com/gsscoder/commandline 11 | 12 | General Info: 13 | This library allows command line arguments parsing. 14 | This work were inspired by the GNU LIBC getopt()/getopt_long() functions 15 | (check out: http://www.gnu.org/software/libc/manual/html_node/Getopt.html). 16 | Need a guide on option naming? Check this one: 17 | http://catb.org/~esr/writings/taoup/html/ch10s05.html. 18 | 19 | More info on: 20 | [QUICKSTART] http://commandline.codeplex.com/wikipage?title=Quickstart&referringTitle=Documentation 21 | [GUIDE] http://commandline.codeplex.com/documentation (*2) 22 | [BLOG] http://gsscoder.github.com/ 23 | 24 | Build (requires Ruby): 25 | MonoDevelop or Visual Studio 26 | 27 | Documentation: 28 | From version 1.9.0.3 Beta CHM HelpFile was removed from {libroot}/doc. 29 | See online documentation section hosted on CodePlex project. 30 | 31 | Framework Compatibility: 32 | - C# 3.0+ compiler 33 | - .NET Framework 2.0+ 34 | - Mono 2.1+ Profile 35 | 36 | Development Environment: 37 | - OS: 38 | Ubuntu 12.04 Desktop (http://www.ubuntu.com/) 39 | Mac OS X Lion (http://www.apple.com/osx/) 40 | Microsoft Windows 7 (http://windows.microsoft.com/en-US/windows/home) 41 | - IDE: 42 | MonoDevelop (http://monodevelop.com/) 43 | MS Visual Studio 2010|2012 (http://www.microsoft.com/visualstudio/eng/visual-studio-update) 44 | - Code Analysis: 45 | JetBrains ReSharper with Open Source License (http://www.jetbrains.com/resharper/) 46 | - Version Control: 47 | Git (http://git-scm.com/) 48 | msysgit (http://code.google.com/p/msysgit/) 49 | SVN (http://subversion.tigris.org/) 50 | - Other Tools: 51 | TextMate (http://macromates.com/) 52 | Scribes (http://scribes.sourceforge.net/) 53 | 54 | Test Environment: 55 | - Mac OS X Lion 56 | - Microsoft Windows 7 57 | - Ubuntu 12.04 58 | 59 | Licence: 60 | MIT License 61 | http://www.opensource.org/licenses/mit-license.php 62 | 63 | Comments, bugs and other: 64 | gsscoder@gmail.com 65 | 66 | Enjoy, 67 | Giacomo Stelluti Scala 68 | 69 | --------------------------------------------------------------------------------------- 70 | [NOTES] 71 | *1) In a production environment you should use a 'stable' version, an 'rc' (release 72 | candidate) or an advanced 'beta' (a 'beta' published for a long time and stated quite stable). 73 | 74 | *2) Full documentation is currently under construction. Please refer to Quickstart 75 | guide and informations published starting from the project's home. 76 | --------------------------------------------------------------------------------------- 77 | -------------------------------------------------------------------------------- /docs/PublicAPI.md: -------------------------------------------------------------------------------- 1 | Public API Changes: 2 | --- 3 | - Version 1.9.4.91: Breaking, short name of an option must be defined as character (``System.Char``). Non breaking, added support for verbs. 4 | - Version 1.9.4.99: Breaking, removed dependency from ``CommandLineOptionsBase``, introduced [ParseStateAttribute](https://github.com/gsscoder/commandline/blob/master/src/sample/Program.cs). 5 | - Version 1.9.4.107: Non breaking, implemented [strict parsing](https://github.com/gsscoder/commandline/blob/master/src/tests/Parser/StrictFixture.cs) (see issue #32). 6 | - Version 1.9.4.109: Non breaking, pull request #44. 7 | - Version 1.9.4.111: Non breaking, ``CommandLineParserSettings``, ``CommandLineParser`` implements ``IDisposable``. 8 | - Version 1.9.4.113: Non breaking, added ``CommandLineParser::WasVerbOptionInvoked`` helper method. 9 | - Version 1.9.4.123: Breaking, ``HandleParsingErrorsDelegate`` renamed to ``ParsingErrorsHandler``, ``MultiLineTextAttribute`` renamed to ``MultilineTextAttribute``. Non breaking, refactoring (see ChangeLog). 10 | - Version 1.9.4.127: 'Partially' non breaking, ``OptionAttribute`` is now sealed. ``OptionArrayAttribute`` and ``OptionListAttribute`` derives from ``BaseOptionAttribute`` (update your custom types too). 11 | - Version 1.9.4.201: Non breaking, introduced ``ValueOptionAttribute`` enhancement of issue #33. 12 | - Version 1.9.4.207: Breaking: ``CommandLineParser``, ``ICommandLineParser``, ``CommandLineParserSettings``, ``CommandLineParserException`` renamed to ``Parser``, ``IParser``, ``ParserSettings``, ``ParserException`` as explained [here](https://github.com/gsscoder/commandline/issues/48). 13 | - Version 1.9.4.209: Non breaking, added fluent builder (``ParserConfigurator``, see issue #42). 14 | - Version 1.9.4.211: 'Partially' non breaking, ParsingErrorsHandler delegate replaced by Action. 15 | - Version 1.9.4.217: Non breaking, Extracted interface ``IParserSettings`` from ``ParserSettings``. Changed consumers to depends on ``IParserSettings`` rather on concrete default implementation. 16 | - Version 1.9.4.219: Non breaking, ``ValueOption`` supports ``Index`` (Remarks: in next Dtable will mandatory). 17 | - Version 1.9.4.223: Non breaking, added ``IParserSettings::ParsingCulture`` and ``ParserConfigurator::UseCulture``. 18 | - Version 1.9.4.225: Breaking, default singleton parsing culture is ``CultureInfo.InvariantCulture``; this is not general default only the one of default singleton. 19 | - Version 1.9.4.223: 'Partially' non breaking, all attributes are now in root namespace. 20 | - Version 1.9.5.0: Breaking (in some cases), removed ``IParser::ParseArguments`` overloads (see ChangeLog); removed ``::WasVerbOptionInvoked``; use new ``HelpText::AutoBuild(object,string)`` instead of obsolete ``::GetVerbOptionsInstanceByName``. 21 | - Version 1.9.6.1: Non breaking (if implicit syntax), reverting back genericity from IParser. 22 | - Version 1.9.61.1: Non breaking, omitting longname default -> property name lower case. 23 | - Version 1.9.62.2: 'Partially' breaking, ``IParserConfigurator`` made nested type of Parser; ``ParserConfigurator::HelpWriter(...)`` renamed to ``ParserConfigurator::UseHelpWriter(...)``. 24 | - Version 1.9.69.1: Breaking (in some cases), removed ``IParser``, ``IParserSettings`` and ``ParserConfigurator``. -------------------------------------------------------------------------------- /docs/content/index.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | // This block of code is omitted in the generated HTML documentation. Use 3 | // it to define helpers that you do not want to show in the documentation. 4 | #I "../../build" 5 | #r "CommandLine.dll" 6 | 7 | open System 8 | 9 | (** 10 | 11 | # Command Line Parser Library 12 | 13 | Terse syntax C# command line parser for .NET with F# support. 14 | 15 |
16 |
17 |
18 |
19 | CommandLineParser can be installed from NuGet: 20 |
PM> Install-Package CommandLineParser -Pre
21 |
22 |
23 |
24 |
25 | 26 | ## Introduction 27 | 28 | The library parses command line arguments to a record decorated with attributes: 29 | *) 30 | 31 | type options = { 32 | [