1 | #Region "Microsoft.VisualBasic::3c024e891522574f02cbf72ad183b6d2, Microsoft.VisualBasic.Core\CommandLine\Interpreters\View\CommandHelp.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 | ' Module CommandHelpExtensions |
35 | ' |
36 | ' Function: PrintCommandHelp |
37 | ' |
38 | ' Sub: listingCommands |
39 | ' |
40 | ' |
41 | ' /********************************************************************************/ |
42 | |
43 | #End Region |
44 | |
45 | Imports System.Runtime.CompilerServices |
46 | Imports Microsoft.VisualBasic.Language |
47 | Imports Microsoft.VisualBasic.Language.UnixBash |
48 | |
49 | Namespace CommandLine.ManView |
50 | |
51 | Module CommandHelpExtensions |
52 | |
53 | <Extension> |
54 | Public Function PrintCommandHelp(app As Interpreter, commandName$) As Integer |
55 | Dim name As New Value(Of String) |
56 | |
57 | If app.__API_table.ContainsKey(name = commandName.ToLower) Then |
58 | Call app.__API_table(name).PrintHelp |
59 | Else |
60 | Dim list$() = app.ListingRelated(commandName) |
61 | |
62 | If list.IsNullOrEmpty Then |
63 | Call Console.WriteLine($"Bad command, no such a command named ""{commandName}"", ? for command list.") |
64 | Call Console.WriteLine() |
65 | Call Console.WriteLine(PS1.Fedora12.ToString & " ?" & commandName) |
66 | Else |
67 | Call app.listingCommands(list, commandName) |
68 | End If |
69 | |
70 | Return -2 |
71 | End If |
72 | |
73 | Return 0 |
74 | End Function |
75 | |
76 | ''' <summary> |
77 | ''' Bad command, no such a command named ""{0}"", but you probably want to using one of these commands: |
78 | ''' </summary> |
79 | Const BAD_COMMAND_LISTING_COMMANDS$ = "Bad command, no such a command named ""{0}"", but you probably want to using one of these commands:" |
80 | |
81 | <Extension> |
82 | Friend Sub listingCommands(app As Interpreter, commands$(), commandName$) |
83 | Call Console.WriteLine(BAD_COMMAND_LISTING_COMMANDS, commandName) |
84 | Call Console.WriteLine() |
85 | |
86 | Dim maxLength = commands.MaxLengthString.Length |
87 | |
88 | For Each cName As String In commands |
89 | With cName |
90 | Dim msg$ |
91 | |
92 | msg$ = .ByRef & New String(" "c, maxLength - .Length + 3) |
93 | |
94 | With app.__API_table(.ToLower).Info |
95 | If Not .StringEmpty Then |
96 | msg$ &= Mid(.ByRef, 1, 60) & "..." |
97 | End If |
98 | End With |
99 | |
100 | Call Console.WriteLine(" " & msg) |
101 | End With |
102 | Next |
103 | End Sub |
104 | End Module |
105 | End Namespace |