File tree Expand file tree Collapse file tree 6 files changed +74
-8
lines changed Expand file tree Collapse file tree 6 files changed +74
-8
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,11 @@ let package:Package = .init(
148
148
. product( name: " OrderedCollections " , package : " swift-collections " ) ,
149
149
] ) ,
150
150
151
+ . target( name: " _GitVersion " ,
152
+ cSettings: [
153
+ . define( " SWIFTPM_GIT_VERSION " , to: " \" \( version) \" " )
154
+ ] ) ,
155
+
151
156
. target( name: " AvailabilityDomain " ) ,
152
157
153
158
. target( name: " Availability " ,
@@ -476,6 +481,7 @@ let package:Package = .init(
476
481
477
482
. target( name: " UnidocCLI " ,
478
483
dependencies: [
484
+ . target( name: " _GitVersion " ) ,
479
485
. target( name: " System_ArgumentParser " ) ,
480
486
. target( name: " UnidocServer " ) ,
481
487
. product( name: " ArgumentParser " , package : " swift-argument-parser " ) ,
@@ -771,3 +777,16 @@ for target:PackageDescription.Target in package.targets
771
777
$0 = settings
772
778
} ( & target. swiftSettings)
773
779
}
780
+
781
+ var version : String
782
+ {
783
+ if let git: GitInformation = Context . gitInformation
784
+ {
785
+ let base : String = git. currentTag ?? git. currentCommit
786
+ return git. hasUncommittedChanges ? " \( base) (modified) " : base
787
+ }
788
+ else
789
+ {
790
+ return " (untracked) "
791
+ }
792
+ }
Original file line number Diff line number Diff line change
1
+ import _GitVersion
2
+
3
+ extension Unidoc
4
+ {
5
+ public
6
+ static var version : String
7
+ {
8
+ . init( cString: _GitVersion. swiftpm_git_version ( ) )
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ #if !defined(SWIFTPM_GIT_VERSION_H )
2
+ #define SWIFTPM_GIT_VERSION_H
3
+
4
+ extern const char * swiftpm_git_version (void );
5
+
6
+ #endif
Original file line number Diff line number Diff line change
1
+ #include "swiftpm_git_version.h"
2
+
3
+ const char * swiftpm_git_version (void )
4
+ {
5
+ return SWIFTPM_GIT_VERSION ;
6
+ }
Original file line number Diff line number Diff line change @@ -32,13 +32,22 @@ struct Main
32
32
name: [ . customLong( " assume-encrypted " ) ] ,
33
33
help: " Assume that the connection is encrypted " )
34
34
var assumeEncrypted : Bool = false
35
+
36
+ @Flag ( name: [ . customLong( " version " ) ] , help: " Print version information and exit " )
37
+ var version : Bool = false
35
38
}
36
39
37
40
@main
38
41
extension Main : AsyncParsableCommand
39
42
{
40
43
func run( ) async throws
41
44
{
45
+ if self . version
46
+ {
47
+ print ( Unidoc . version)
48
+ return
49
+ }
50
+
42
51
NIOSingletons . groupLoopCountSuggestion = 2
43
52
44
53
let clientIdentity : NIOSSLContext = try . clientDefault
Original file line number Diff line number Diff line change @@ -2,13 +2,29 @@ import ArgumentParser
2
2
import SymbolGraphCompiler
3
3
4
4
@main
5
- struct Main : AsyncParsableCommand
5
+ struct Main
6
6
{
7
- static let configuration : CommandConfiguration = . init( subcommands: [
8
- SSGC . CompileCommand. self,
9
- Unidoc . InitCommand. self,
10
- Unidoc . LocalCommand. self,
11
- Unidoc . PreviewCommand. self,
12
- Unidoc . ListAssetsCommand. self,
13
- ] )
7
+ @Flag ( name: [ . customLong( " version " ) ] , help: " Print version information and exit " )
8
+ var version : Bool = false
9
+ }
10
+ extension Main : AsyncParsableCommand
11
+ {
12
+ static var configuration : CommandConfiguration
13
+ {
14
+ . init( subcommands: [
15
+ SSGC . CompileCommand. self,
16
+ Unidoc . InitCommand. self,
17
+ Unidoc . LocalCommand. self,
18
+ Unidoc . PreviewCommand. self,
19
+ Unidoc . ListAssetsCommand. self,
20
+ ] )
21
+ }
22
+
23
+ func run( ) async throws
24
+ {
25
+ if self . version
26
+ {
27
+ print ( Unidoc . version)
28
+ }
29
+ }
14
30
}
You can’t perform that action at this time.
0 commit comments