| 1 | #Region "Microsoft.VisualBasic::192cbfb59a9a77193050b90403cc8b05, Microsoft.VisualBasic.Core\CommandLine\Reflection\Attributes\Argument.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Class Argument |
| 35 | ' |
| 36 | ' Properties: [Optional], AcceptTypes, Description, Example, Extensions |
| 37 | ' Name, Out, Pipeline, TokenType, Usage |
| 38 | ' |
| 39 | ' Constructor: (+1 Overloads) Sub New |
| 40 | ' Function: ToString |
| 41 | ' |
| 42 | ' |
| 43 | ' /********************************************************************************/ |
| 44 | |
| 45 | #End Region |
| 46 | |
| 47 | Imports System.Text |
| 48 | Imports Microsoft.VisualBasic.CommandLine.ManView |
| 49 | Imports Microsoft.VisualBasic.Text |
| 50 | |
| 51 | Namespace CommandLine.Reflection |
| 52 | |
| 53 | ''' <summary> |
| 54 | ''' Use for the detail description for a specific commandline switch.(用于对某一个命令的开关参数的具体描述帮助信息) |
| 55 | ''' </summary> |
| 56 | ''' <remarks></remarks> |
| 57 | <AttributeUsage(AttributeTargets.Method, AllowMultiple:=True, Inherited:=True)> |
| 58 | Public Class Argument : Inherits CLIToken |
| 59 | |
| 60 | ''' <summary> |
| 61 | ''' The name of this command line parameter switch.(该命令开关的名称) |
| 62 | ''' </summary> |
| 63 | ''' <value></value> |
| 64 | ''' <returns></returns> |
| 65 | ''' <remarks></remarks> |
| 66 | Public Overrides ReadOnly Property Name As String |
| 67 | Get |
| 68 | Return MyBase.Name |
| 69 | End Get |
| 70 | End Property |
| 71 | |
| 72 | Dim describ As String |
| 73 | |
| 74 | ''' <summary> |
| 75 | ''' The description and brief help information about this parameter switch, |
| 76 | ''' you can using the ``\n`` escape string to gets a ``VbCrLf`` value. |
| 77 | ''' (对这个开关参数的具体的描述以及帮助信息,可以使用``\n``转义字符进行换行) |
| 78 | ''' </summary> |
| 79 | ''' <value></value> |
| 80 | ''' <returns></returns> |
| 81 | ''' <remarks></remarks> |
| 82 | Public Property Description As String |
| 83 | Get |
| 84 | Return describ |
| 85 | End Get |
| 86 | Set(value As String) |
| 87 | Dim tokens$() = Strings.Split(value, "\n") |
| 88 | Dim sb As New StringBuilder(tokens.First & vbCrLf) |
| 89 | |
| 90 | For i As Integer = 1 To tokens.Length - 1 |
| 91 | Call sb.AppendLine(" " & tokens(i)) |
| 92 | Next |
| 93 | |
| 94 | describ = sb.ToString |
| 95 | End Set |
| 96 | End Property |
| 97 | |
| 98 | ''' <summary> |
| 99 | ''' The usage example of this parameter switch.(该开关的值的示例) |
| 100 | ''' |
| 101 | ''' ``` |
| 102 | ''' name example |
| 103 | ''' ``` |
| 104 | ''' </summary> |
| 105 | ''' <value></value> |
| 106 | ''' <returns></returns> |
| 107 | ''' <remarks></remarks> |
| 108 | Public ReadOnly Property Example As String |
| 109 | Get |
| 110 | If TokenType = CLITypes.Boolean Then |
| 111 | Return Name |
| 112 | Else |
| 113 | Return $"{Name} {ExampleValue}" |
| 114 | End If |
| 115 | End Get |
| 116 | End Property |
| 117 | |
| 118 | ''' <summary> |
| 119 | ''' The usage syntax information about this parameter switch.(本开关参数的使用语法) |
| 120 | ''' </summary> |
| 121 | ''' <value></value> |
| 122 | ''' <returns></returns> |
| 123 | ''' <remarks></remarks> |
| 124 | Public Property Usage As String |
| 125 | |
| 126 | ''' <summary> |
| 127 | ''' Is this parameter switch is an optional value.(本开关是否为可选的参数) |
| 128 | ''' </summary> |
| 129 | ''' <value></value> |
| 130 | ''' <returns></returns> |
| 131 | ''' <remarks></remarks> |
| 132 | Public ReadOnly Property [Optional] As Boolean |
| 133 | Public ReadOnly Property TokenType As CLITypes |
| 134 | Public ReadOnly Property Pipeline As PipelineTypes |
| 135 | |
| 136 | ''' <summary> |
| 137 | ''' Is this parameter is using for the output |
| 138 | ''' </summary> |
| 139 | ''' <returns></returns> |
| 140 | Public Property Out As Boolean = False |
| 141 | ''' <summary> |
| 142 | ''' Accept these types as input or output data in this types if <see cref="Out"/> is true. |
| 143 | ''' </summary> |
| 144 | ''' <returns></returns> |
| 145 | Public Property AcceptTypes As Type() |
| 146 | |
| 147 | ''' <summary> |
| 148 | ''' Example: |
| 149 | ''' |
| 150 | ''' ``` |
| 151 | ''' csv, json, txt |
| 152 | ''' ``` |
| 153 | ''' |
| 154 | ''' Extension for the document format <see cref="AcceptTypes"/> if this argument its <see cref="TokenType"/> is a <see cref="CLITypes.File"/> |
| 155 | ''' If supports multiple extension, delimiter using ``,`` comma symbol. |
| 156 | ''' </summary> |
| 157 | ''' <returns></returns> |
| 158 | Public Property Extensions As String |
| 159 | |
| 160 | ''' <summary> |
| 161 | ''' 对命令行之中的某一个参数进行描述性信息的创建,包括用法和含义 |
| 162 | ''' </summary> |
| 163 | ''' <param name="Name">The name of this command line parameter switch.(该命令开关的名称)</param> |
| 164 | ''' <param name="Optional">Is this parameter switch is an optional value.(本开关是否为可选的参数)</param> |
| 165 | ''' <remarks></remarks> |
| 166 | Sub New(name$, |
| 167 | Optional [Optional] As Boolean = False, |
| 168 | Optional type As CLITypes = CLITypes.String, |
| 169 | Optional pip As PipelineTypes = PipelineTypes.undefined) |
| 170 | |
| 171 | Call MyBase.New(name) |
| 172 | |
| 173 | Me.[Optional] = [Optional] |
| 174 | Me.TokenType = type |
| 175 | Me.Pipeline = pip |
| 176 | End Sub |
| 177 | |
| 178 | Public Overrides Function ToString() As String |
| 179 | Dim sb As New StringBuilder(1024) |
| 180 | Dim example$ = ExampleValue |
| 181 | Dim descripts$() = Paragraph.SplitParagraph(Description, 80).ToArray |
| 182 | |
| 183 | If [Optional] Then |
| 184 | sb.AppendLine(String.Format(" [{0}]", Name)) |
| 185 | Else |
| 186 | sb.AppendLine(" " & Name) |
| 187 | End If |
| 188 | sb.AppendLine(String.Format(" Description: {0}", descripts.FirstOrDefault)) |
| 189 | |
| 190 | If descripts.Length > 1 Then |
| 191 | For Each line$ In descripts.Skip(1) |
| 192 | sb.AppendLine(" " & line) |
| 193 | Next |
| 194 | End If |
| 195 | |
| 196 | If TokenType = CLITypes.Boolean Then |
| 197 | sb.AppendLine($" Example: {Name}") |
| 198 | sb.AppendLine($" {boolFlag}") |
| 199 | Else |
| 200 | sb.AppendLine(String.Format(" Example: {0} {1}", Name, example)) |
| 201 | If Pipeline <> PipelineTypes.undefined Then |
| 202 | sb.AppendLine($" " & Pipeline.Description) |
| 203 | End If |
| 204 | End If |
| 205 | |
| 206 | Return sb.ToString |
| 207 | End Function |
| 208 | End Class |
| 209 | End Namespace |