2018-11-08 20:21:25 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::8bfe84fb501b81f8d91b8612e4adce17, Microsoft.VisualBasic.Core\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 22:41:14 +08:00
|
|
|
|
' 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))
|
2018-11-02 22:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
Call $"{api.EntryPointFullName(relativePath:=True)} is nothing!".Warning
|
|
|
|
|
|
Else
|
|
|
|
|
|
usageCommand = apiUsage.CommandLineModel
|
|
|
|
|
|
End If
|
|
|
|
|
|
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Try
|
|
|
|
|
|
help =
|
|
|
|
|
|
$"```
|
2018-11-02 22:41:14 +08:00
|
|
|
|
{apiUsage.Replace("<", "<")}
|
2018-08-02 20:14:48 +08:00
|
|
|
|
```" & vbCrLf & api.Info
|
|
|
|
|
|
|
|
|
|
|
|
CLI = New NamedValue(Of CommandLine) With {
|
|
|
|
|
|
.Name = api.EntryPoint.Name,
|
|
|
|
|
|
.Description = help,
|
2018-11-02 22:41:14 +08:00
|
|
|
|
.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
|