/
ArgumentSynopsis.swift
42 lines (38 loc) · 1.3 KB
/
ArgumentSynopsis.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//===----------------------------------------------------------*- swift -*-===//
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
import ArgumentParser
import ArgumentParserToolInfo
struct ArgumentSynopsis: MDocComponent {
var argument: ArgumentInfoV0
var body: MDocComponent {
if argument.isOptional {
MDocMacro.OptionalCommandLineComponent(arguments: [synopsis])
} else {
synopsis
}
}
// ArgumentInfoV0 formatted as MDoc without optional bracket wrapper.
var synopsis: MDocASTNode {
switch argument.kind {
case .positional:
return argument.manualPageDescription
case .option:
// preferredName cannot be nil
let name = argument.preferredName!
return MDocMacro.CommandOption(options: [name.manualPage])
.withUnsafeChildren(nodes: [argument.manualPageValueName])
case .flag:
// preferredName cannot be nil
let name = argument.preferredName!
return MDocMacro.CommandOption(options: [name.manualPage])
}
}
}