microsoft-visualbasic-runtime/CommandLine/InteropService/SharedORM/CodeGenerator.vb

140 lines
4.5 KiB
VB.net
Raw Normal View History

2019-07-17 22:01:31 +08:00
#Region "Microsoft.VisualBasic::dee18c385910bba9c50b797ed61de515, CommandLine\InteropService\SharedORM\CodeGenerator.vb"
2018-08-02 20:14:48 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Class CodeGenerator
'
' Constructor: (+2 Overloads) Sub New
' Function: EnumeratesAPI, GetManualPage
'
' Class APITuple
'
' Properties: API, CLI
'
'
' /********************************************************************************/
#End Region
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic.CommandLine.ManView
Imports Microsoft.VisualBasic.CommandLine.Reflection.EntryPoints
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
2018-11-02 23:56:43 +08:00
Imports Microsoft.VisualBasic.Language
2018-08-02 20:14:48 +08:00
Namespace CommandLine.InteropService.SharedORM
Public MustInherit Class CodeGenerator
Protected ReadOnly App As Interpreter
''' <summary>
''' 目标应用程序模块的文件名,不包含有文件拓展名
''' </summary>
Protected ReadOnly exe$
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Sub New(CLI As Type)
Call Me.New(New Interpreter(type:=CLI))
End Sub
Sub New(App As Interpreter)
Me.App = App
Me.exe = App.Type _
.Assembly _
.CodeBase _
.BaseName
End Sub
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Function GetManualPage() As String
Return App.HelpSummary(markdown:=False)
End Function
Public MustOverride Function GetSourceCode() As String
Public Iterator Function EnumeratesAPI() As IEnumerable(Of APITuple)
Dim help$
Dim CLI As NamedValue(Of CommandLine)
For Each api As APIEntryPoint In App.APIList
' 2018-11-02 usage是空的说明可能没有额外的参数只需要调用命令即可
' 在这里Usage可能是空值
Dim apiUsage$ = api.Usage Or EmptyString
Dim usageCommand As CommandLine
If apiUsage.StringEmpty Then
usageCommand = New CommandLine With {
2018-11-02 23:56:43 +08:00
.Name = api.Name,
.BoolFlags = {},
.cliCommandArgvs = api.Name,
.SingleValue = api.Name,
.Tokens = {api.Name},
.__arguments = New List(Of NamedValue(Of String))
}
Call $"{api.EntryPointFullName(relativePath:=True)} is nothing!".Warning
Else
usageCommand = apiUsage.CommandLineModel
End If
2018-08-02 20:14:48 +08:00
Try
help =
$"```
{apiUsage.Replace("<", "&lt;")}
2018-08-02 20:14:48 +08:00
```" & vbCrLf & api.Info
CLI = New NamedValue(Of CommandLine) With {
.Name = api.EntryPoint.Name,
.Description = help,
.Value = usageCommand
2018-08-02 20:14:48 +08:00
}
Yield New APITuple With {
.CLI = CLI,
.API = api.EntryPoint
}
Catch ex As Exception
ex = New Exception(api.EntryPointFullName(False), ex)
Throw ex
End Try
Next
End Function
End Class
Public Class APITuple
Public Property CLI As NamedValue(Of CommandLine)
Public Property API As MethodInfo
End Class
End Namespace