From c709003b78004c8520c7fde20745bd966c6de527 Mon Sep 17 00:00:00 2001 From: Peter Pitterling Date: Thu, 10 Nov 2016 14:50:30 +0100 Subject: [PATCH 1/4] ReadText.Demo.VB - initial commit --- .gitignore | 2 + demo/ReadText.Demo.VB/App.config | 6 + .../My Project/Application.Designer.vb | 13 ++ .../My Project/Application.myapp | 10 ++ .../My Project/AssemblyInfo.vb | 35 +++++ .../My Project/Resources.Designer.vb | 63 ++++++++ .../My Project/Resources.resx | 117 ++++++++++++++ .../My Project/Settings.Designer.vb | 73 +++++++++ .../My Project/Settings.settings | 7 + demo/ReadText.Demo.VB/My Project/app.manifest | 76 +++++++++ demo/ReadText.Demo.VB/Program.vb | 7 + demo/ReadText.Demo.VB/ReadText.Demo.VB.sln | 22 +++ demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj | 148 ++++++++++++++++++ .../ReadText.Demo.VB.vbproj.user | 13 ++ demo/ReadText.Demo.VB/packages.config | 4 + 15 files changed, 596 insertions(+) create mode 100644 demo/ReadText.Demo.VB/App.config create mode 100644 demo/ReadText.Demo.VB/My Project/Application.Designer.vb create mode 100644 demo/ReadText.Demo.VB/My Project/Application.myapp create mode 100644 demo/ReadText.Demo.VB/My Project/AssemblyInfo.vb create mode 100644 demo/ReadText.Demo.VB/My Project/Resources.Designer.vb create mode 100644 demo/ReadText.Demo.VB/My Project/Resources.resx create mode 100644 demo/ReadText.Demo.VB/My Project/Settings.Designer.vb create mode 100644 demo/ReadText.Demo.VB/My Project/Settings.settings create mode 100644 demo/ReadText.Demo.VB/My Project/app.manifest create mode 100644 demo/ReadText.Demo.VB/Program.vb create mode 100644 demo/ReadText.Demo.VB/ReadText.Demo.VB.sln create mode 100644 demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj create mode 100644 demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj.user create mode 100644 demo/ReadText.Demo.VB/packages.config diff --git a/.gitignore b/.gitignore index eb52d2c0..2f2f78c8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ src/CommandLine.dotnet/bin/* src/CommandLine.dotnet/obj demo/ReadText.Demo/bin/* demo/ReadText.Demo/obj +/demo/ReadText.Demo.VB/bin/* +/demo/ReadText.Demo.VB/obj tests/CommandLine.Tests/bin/* tests/CommandLine.Tests/obj tests/CommandLine.DotNet.Tests/bin/* diff --git a/demo/ReadText.Demo.VB/App.config b/demo/ReadText.Demo.VB/App.config new file mode 100644 index 00000000..74ade9db --- /dev/null +++ b/demo/ReadText.Demo.VB/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/demo/ReadText.Demo.VB/My Project/Application.Designer.vb b/demo/ReadText.Demo.VB/My Project/Application.Designer.vb new file mode 100644 index 00000000..88dd01c7 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/demo/ReadText.Demo.VB/My Project/Application.myapp b/demo/ReadText.Demo.VB/My Project/Application.myapp new file mode 100644 index 00000000..e62f1a53 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 2 + true + diff --git a/demo/ReadText.Demo.VB/My Project/AssemblyInfo.vb b/demo/ReadText.Demo.VB/My Project/AssemblyInfo.vb new file mode 100644 index 00000000..f2e725d4 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + + + + + + + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/demo/ReadText.Demo.VB/My Project/Resources.Designer.vb b/demo/ReadText.Demo.VB/My Project/Resources.Designer.vb new file mode 100644 index 00000000..8e2454d9 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("ReadText.Demo.VB.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/demo/ReadText.Demo.VB/My Project/Resources.resx b/demo/ReadText.Demo.VB/My Project/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/demo/ReadText.Demo.VB/My Project/Settings.Designer.vb b/demo/ReadText.Demo.VB/My Project/Settings.Designer.vb new file mode 100644 index 00000000..f54db15b --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.ReadText.Demo.VB.My.MySettings + Get + Return Global.ReadText.Demo.VB.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/demo/ReadText.Demo.VB/My Project/Settings.settings b/demo/ReadText.Demo.VB/My Project/Settings.settings new file mode 100644 index 00000000..85b890b3 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/demo/ReadText.Demo.VB/My Project/app.manifest b/demo/ReadText.Demo.VB/My Project/app.manifest new file mode 100644 index 00000000..a6b46bb7 --- /dev/null +++ b/demo/ReadText.Demo.VB/My Project/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/ReadText.Demo.VB/Program.vb b/demo/ReadText.Demo.VB/Program.vb new file mode 100644 index 00000000..be763a90 --- /dev/null +++ b/demo/ReadText.Demo.VB/Program.vb @@ -0,0 +1,7 @@ +Module Program + + Sub Main() + + End Sub + +End Module diff --git a/demo/ReadText.Demo.VB/ReadText.Demo.VB.sln b/demo/ReadText.Demo.VB/ReadText.Demo.VB.sln new file mode 100644 index 00000000..8b156856 --- /dev/null +++ b/demo/ReadText.Demo.VB/ReadText.Demo.VB.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ReadText.Demo.VB", "ReadText.Demo.VB.vbproj", "{298FBAFF-C828-4BF9-8E93-2BE925E9E223}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Debug|Any CPU.Build.0 = Debug|Any CPU + {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Release|Any CPU.ActiveCfg = Release|Any CPU + {298FBAFF-C828-4BF9-8E93-2BE925E9E223}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj new file mode 100644 index 00000000..a848f818 --- /dev/null +++ b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj @@ -0,0 +1,148 @@ + + + + + Debug + AnyCPU + {298FBAFF-C828-4BF9-8E93-2BE925E9E223} + Exe + ReadText.Demo.VB.Program + ReadText.Demo.VB + ReadText.Demo.VB + 512 + Console + v4.0 + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + AnyCPU + true + full + true + true + bin\Debug\ + ReadText.Demo.VB.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false + + + AnyCPU + pdbonly + false + true + true + bin\Release\ + ReadText.Demo.VB.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + My Project\app.manifest + + + + packages\CommandLineParser.2.1.1-beta\lib\net40\CommandLine.dll + True + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + + False + Microsoft .NET Framework 4.5.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj.user b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj.user new file mode 100644 index 00000000..82213335 --- /dev/null +++ b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj.user @@ -0,0 +1,13 @@ + + + + publish\ + + + + + + en-US + false + + \ No newline at end of file diff --git a/demo/ReadText.Demo.VB/packages.config b/demo/ReadText.Demo.VB/packages.config new file mode 100644 index 00000000..d34c1336 --- /dev/null +++ b/demo/ReadText.Demo.VB/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 31314dfa25b3c604bdd0c8e5b065913138067fb4 Mon Sep 17 00:00:00 2001 From: Peter Pitterling Date: Thu, 10 Nov 2016 16:21:45 +0100 Subject: [PATCH 2/4] Options.vb - IOptions,HeadOptions,TailOptions --- demo/ReadText.Demo.VB/Options.vb | 43 +++++++++++++++++++ demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj | 1 + 2 files changed, 44 insertions(+) create mode 100644 demo/ReadText.Demo.VB/Options.vb diff --git a/demo/ReadText.Demo.VB/Options.vb b/demo/ReadText.Demo.VB/Options.vb new file mode 100644 index 00000000..6e5b737a --- /dev/null +++ b/demo/ReadText.Demo.VB/Options.vb @@ -0,0 +1,43 @@ +Imports CommandLine + +Public Interface IOptions + + <[Option]("n"c, "lines", SetName:="bylines", [Default]:=5UI, HelpText:="CPU source file to read.")> + Property Lines As UInteger? + + <[Option]("c"c, "bytes", SetName:="bybytes", HelpText:="Bytes to be printed from the beginning or end of the file.")> + Property Bytes As UInteger? + + <[Option]("q"c, "quiet", HelpText:="Supresses summary messages.")> + Property Quiet As Boolean + + <[Value](0, MetaName:="input file", Required:=True, HelpText:="Input file to be processed.")> + Property FileName As String + +End Interface + +<[Verb]("head", HelpText:="Displays first lines of a file.")> +Public Class HeadOptions + Implements IOptions + Public Property Lines As UInteger? Implements IOptions.Lines + + Public Property Bytes As UInteger? Implements IOptions.Bytes + + Public Property Quiet As Boolean Implements IOptions.Quiet + + Public Property FileName As String Implements IOptions.FileName + +End Class + +<[Verb]("tail", HelpText:="Displays last lines of a file.")> +Public Class TailOptions + Implements IOptions + Public Property Lines As UInteger? Implements IOptions.Lines + + Public Property Bytes As UInteger? Implements IOptions.Bytes + + Public Property Quiet As Boolean Implements IOptions.Quiet + + Public Property FileName As String Implements IOptions.FileName + +End Class diff --git a/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj index a848f818..29450891 100644 --- a/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj +++ b/demo/ReadText.Demo.VB/ReadText.Demo.VB.vbproj @@ -86,6 +86,7 @@ + From bcabeb472e4f57cbe093accd53f93ca891646505 Mon Sep 17 00:00:00 2001 From: Peter Pitterling Date: Thu, 10 Nov 2016 17:02:11 +0100 Subject: [PATCH 3/4] ReadLines + ReadBytes --- demo/ReadText.Demo.VB/Program.vb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/demo/ReadText.Demo.VB/Program.vb b/demo/ReadText.Demo.VB/Program.vb index be763a90..3e3a01dc 100644 --- a/demo/ReadText.Demo.VB/Program.vb +++ b/demo/ReadText.Demo.VB/Program.vb @@ -1,7 +1,35 @@ -Module Program +Imports System +Imports System.IO +Imports System.Linq +Imports System.Text +Imports CommandLine - Sub Main() +Module Program + + Sub Main(ByVal sArgs() As String) End Sub + Private Function ReadLines(fileName As String, fromTop As Boolean, count As Integer) As String + + Dim lines = File.ReadAllLines(fileName) + If (fromTop) Then + Return String.Join(Environment.NewLine, lines.Take(count)) + End If + + Return String.Join(Environment.NewLine, lines.Reverse().Take(count)) + + End Function + + Private Function ReadBytes(fileName As String, fromTop As Boolean, count As Integer) As String + + Dim bytes = File.ReadAllBytes(fileName) + If (fromTop) Then + Return Encoding.UTF8.GetString(bytes, 0, count) + End If + + Return Encoding.UTF8.GetString(bytes, bytes.Length - count, count) + + End Function + End Module From 806d2d243472ad70ef7e917dcc66e4be862e5058 Mon Sep 17 00:00:00 2001 From: Peter Pitterling Date: Thu, 10 Nov 2016 17:48:18 +0100 Subject: [PATCH 4/4] finish Main --- demo/ReadText.Demo.VB/Program.vb | 47 ++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/demo/ReadText.Demo.VB/Program.vb b/demo/ReadText.Demo.VB/Program.vb index 3e3a01dc..4ddec61e 100644 --- a/demo/ReadText.Demo.VB/Program.vb +++ b/demo/ReadText.Demo.VB/Program.vb @@ -1,14 +1,45 @@ -Imports System -Imports System.IO -Imports System.Linq +Imports System.IO Imports System.Text Imports CommandLine Module Program - Sub Main(ByVal sArgs() As String) + Function Main(ByVal sArgs() As String) As Integer - End Sub + Dim reader As Func(Of IOptions, String) = Function(opts) + Dim fromTop = opts.[GetType]() = GetType(HeadOptions) + Return If(opts.Lines.HasValue, ReadLines(opts.FileName, fromTop, CInt(opts.Lines)), ReadBytes(opts.FileName, fromTop, CInt(opts.Bytes))) + End Function + + Dim header As Func(Of IOptions, String) = Function(opts) + If opts.Quiet Then Return String.Empty + + Dim fromTop = opts.[GetType]() = GetType(HeadOptions) + Dim builder = New StringBuilder("Reading ") + builder = If(opts.Lines.HasValue, builder.Append(opts.Lines).Append(" lines"), builder.Append(opts.Bytes).Append(" bytes")) + builder = If(fromTop, builder.Append(" from top:"), builder.Append(" from bottom:")) + Return builder.ToString() + + End Function + + Dim printIfNotEmpty As Action(Of String) = Sub(text) + If text.Length = 0 Then Return + Console.WriteLine(text) + End Sub + + Dim result = Parser.Default.ParseArguments(Of HeadOptions, TailOptions)(sArgs) + + Dim texts = result.MapResult( + Function(opts As HeadOptions) Tuple.Create(header(opts), reader(opts)), + Function(opts As TailOptions) Tuple.Create(header(opts), reader(opts)), + Function() MakeError()) + + printIfNotEmpty(texts.Item1) + printIfNotEmpty(texts.Item2) + + Return If(texts.Equals(MakeError()), 1, 0) + + End Function Private Function ReadLines(fileName As String, fromTop As Boolean, count As Integer) As String @@ -32,4 +63,10 @@ Module Program End Function + Private Function MakeError() As Tuple(Of String, String) + + Return Tuple.Create(vbNullChar, vbNullChar) + + End Function + End Module