Skip to content

Commit 106a5dc

Browse files
committed
get url from args
1 parent 507f177 commit 106a5dc

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Fetch ssl certificates from https urls and store them in different formats.
1717
Prints the certificates of a given URL.
1818

1919
```bash
20-
cert-fetcher --url https://www.foo.bar
20+
cert-fetcher https://www.foo.bar
2121

2222
# All options
2323
cert-fetcher --help
@@ -28,7 +28,7 @@ cert-fetcher --help
2828
Stores the certificates from the given URL into a pem file.
2929

3030
```bash
31-
cert-fetcher pem --url https://www.foo.bar
31+
cert-fetcher pem https://www.foo.bar
3232

3333
# All options
3434
cert-fetcher pem --help
@@ -39,7 +39,7 @@ cert-fetcher pem --help
3939
Stores the certificates from the given URL into a java keystore file.
4040

4141
```bash
42-
cert-fetcher jks --url https://www.foo.bar
42+
cert-fetcher jks https://www.foo.bar
4343

4444
# All options
4545
cert-fetcher jks --help

cmd/jks.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ var (
1212

1313
// jksCmd represents the jks command
1414
var jksCmd = &cobra.Command{
15-
Version: version,
16-
Use: "jks",
17-
Short: "store the certificates into an java keystore",
18-
Long: "store the certificates into an java keystore",
15+
Version: version,
16+
Use: "jks [url]",
17+
Short: "store the certificates into an java keystore",
18+
Long: "store the certificates into an java keystore",
19+
Args: cobra.ExactArgs(1),
20+
ValidArgs: []string{"url"},
1921
RunE: func(cmd *cobra.Command, args []string) error {
20-
return jks.Export(targetURL, certIndexes, jksSource, jksPassword, outputFile)
22+
return jks.Export(args[0], certIndexes, jksSource, jksPassword, outputFile)
2123
},
2224
}
2325

cmd/pem.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77

88
// pemCmd represents the pem command
99
var pemCmd = &cobra.Command{
10-
Version: version,
11-
Use: "pem",
12-
Short: "store the certificates as pem file",
13-
Long: "store the certificates as pem file",
14-
10+
Version: version,
11+
Use: "pem [url]",
12+
Short: "store the certificates as pem file",
13+
Long: "store the certificates as pem file",
14+
ValidArgs: []string{"url"},
15+
Args: cobra.ExactArgs(1),
1516
RunE: func(cmd *cobra.Command, args []string) error {
16-
return pem.ExportTo(targetURL, certIndexes, outputFile)
17+
return pem.ExportTo(args[0], certIndexes, outputFile)
1718
},
1819
}
1920

cmd/root.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ import (
99
)
1010

1111
var (
12-
targetURL string
1312
outputFile string
1413
certIndexes []int
1514
version string
1615
)
1716

1817
// rootCmd represents the base command when called without any subcommands
1918
var rootCmd = &cobra.Command{
20-
Version: version,
21-
Use: "cert-fetcher",
22-
Short: "Fetch client certificates from https urls",
23-
Long: "A go application that fetches public certificates from https sites and stores them into different output formates.",
19+
Version: version,
20+
Use: "cert-fetcher [url]",
21+
Short: "Fetch client certificates from https urls",
22+
Long: "A go application that fetches public certificates from https sites and stores them into different output formats.",
23+
ValidArgs: []string{"url"},
24+
Args: cobra.ExactArgs(1),
2425
RunE: func(cmd *cobra.Command, args []string) error {
25-
return cert.Print(targetURL)
26+
return cert.Print(args[0])
2627
},
2728
}
2829

@@ -36,8 +37,6 @@ func Execute() {
3637
}
3738

3839
func init() {
39-
rootCmd.PersistentFlags().StringVarP(&targetURL, "url", "u", "", "the URL to fetch the certificate from")
40-
_ = rootCmd.MarkPersistentFlagRequired("url")
4140
rootCmd.PersistentFlags().StringVarP(&outputFile, "out-file", "o", "", "the output file")
4241
rootCmd.PersistentFlags().IntSliceVarP(&certIndexes, "import-at", "i", make([]int, 0), "import the certificates at the given indexes")
4342
}

0 commit comments

Comments
 (0)