Skip to content

Commit 2041db1

Browse files
fix: Exit after printing version or help message (#32)
* fix: Exit after printing version or help message * Update .gitignore
1 parent 197aa09 commit 2041db1

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,31 @@ target-jsonl-blob
2323
# vendor/
2424

2525
dist/
26+
27+
# General
28+
.DS_Store
29+
.AppleDouble
30+
.LSOverride
31+
32+
# Icon must end with two \r
33+
Icon
34+
35+
36+
# Thumbnails
37+
._*
38+
39+
# Files that might appear in the root of a volume
40+
.DocumentRevisions-V100
41+
.fseventsd
42+
.Spotlight-V100
43+
.TemporaryItems
44+
.Trashes
45+
.VolumeIcon.icns
46+
.com.apple.timemachine.donotpresent
47+
48+
# Directories potentially created on remote AFP share
49+
.AppleDB
50+
.AppleDesktop
51+
Network Trash Folder
52+
Temporary Items
53+
.apdisk

cmd/root.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@ var rootCmd = &cobra.Command{
4343

4444
// Execute adds all child commands to the root command and sets flags appropriately.
4545
// This is called by main.main(). It only needs to happen once to the rootCmd.
46-
func Execute() {
46+
func Execute(version string) {
47+
rootCmd.Version = version
48+
4749
err := rootCmd.Execute()
4850
if err != nil {
4951
os.Exit(1)
5052
}
5153

54+
if printVersion, _ := rootCmd.Flags().GetBool("version"); printVersion {
55+
os.Exit(0)
56+
}
57+
58+
if printHelp, _ := rootCmd.Flags().GetBool("help"); printHelp {
59+
os.Exit(0)
60+
}
61+
5262
if err := target.ReadConfig(configFile, &config); err != nil {
5363
log.Fatalf("unable to decode into struct, %v", err)
5464
}
@@ -70,6 +80,9 @@ func Execute() {
7080

7181
func init() {
7282
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file")
73-
rootCmd.PersistentFlags().StringVarP(&inputFile, "input", "i", "", "Input file")
83+
rootCmd.MarkPersistentFlagFilename("config", "json")
7484
rootCmd.MarkPersistentFlagRequired("config")
85+
86+
rootCmd.PersistentFlags().StringVarP(&inputFile, "input", "i", "", "Input file")
87+
rootCmd.MarkPersistentFlagFilename("input")
7588
}

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package main
1717

1818
import "meltano.com/target-jsonl-blob/cmd"
1919

20+
// goreleaser injected values
21+
var version = "dev"
22+
2023
func main() {
21-
cmd.Execute()
24+
cmd.Execute(version)
2225
}

0 commit comments

Comments
 (0)