Skip to content

Commit

Permalink
Implement --no-expand flag to allow disabling expansion of file indices
Browse files Browse the repository at this point in the history
  • Loading branch information
clelange committed Sep 28, 2020
1 parent a00514f commit 25c46a4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# cernopendata-client-go

Go implementation of the CERN Open Data client

Please see the [autogenerated docs](docs/cernopendata-client-go.md).
2 changes: 1 addition & 1 deletion cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ with a record.`,
if err != nil {
er(err)
}
filesList, err := getFilesList(recordJSON, true)
filesList, err := getFilesList(recordJSON)
if err != nil {
er(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
if err != nil {
er(err)
}
filesList, err := getFilesList(recordJSON, true)
filesList, err := getFilesList(recordJSON)
if err != nil {
er(err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
// Used for flags.
recordID string
server string
noExpand bool

rootCmd = &cobra.Command{
Use: "cernopendata-client-go",
Expand All @@ -36,6 +37,7 @@ func Execute() error {
func init() {

rootCmd.PersistentFlags().StringVarP(&recordID, "record", "r", "", "record ID to list (required)")
rootCmd.PersistentFlags().BoolVar(&noExpand, "no-expand", false, "expand files indices")
rootCmd.MarkFlagRequired("record")
rootCmd.PersistentFlags().StringVarP(&server, "server", "s", "http://opendata.cern.ch", "CERN Open Data server to query")
err := doc.GenMarkdownTree(rootCmd, "docs")
Expand Down Expand Up @@ -122,7 +124,7 @@ func getRecordJSON() (map[string]interface{}, error) {

}

func getFilesList(recordJSON map[string]interface{}, expand bool) ([]string, error) {
func getFilesList(recordJSON map[string]interface{}) ([]string, error) {

_, hasMetadata := recordJSON["metadata"]
filesSlice := make([]string, 0)
Expand All @@ -141,7 +143,7 @@ func getFilesList(recordJSON map[string]interface{}, expand bool) ([]string, err
}
}

if expand {
if !noExpand {
filesSliceExpanded := make([]string, 0)
for idx := range filesSlice {
if strings.HasSuffix(filesSlice[idx], "_file_index.txt") {
Expand Down
1 change: 1 addition & 0 deletions docs/cernopendata-client-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ files and complete records.

```
-h, --help help for cernopendata-client-go
--no-expand expand files indices
-r, --record string record ID to list (required)
-s, --server string CERN Open Data server to query (default "http://opendata.cern.ch")
```
Expand Down
1 change: 1 addition & 0 deletions docs/cernopendata-client-go_download.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cernopendata-client-go download [flags]
### Options inherited from parent commands

```
--no-expand expand files indices
-r, --record string record ID to list (required)
-s, --server string CERN Open Data server to query (default "http://opendata.cern.ch")
```
Expand Down
1 change: 1 addition & 0 deletions docs/cernopendata-client-go_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cernopendata-client-go list [flags]
### Options inherited from parent commands

```
--no-expand expand files indices
-r, --record string record ID to list (required)
-s, --server string CERN Open Data server to query (default "http://opendata.cern.ch")
```
Expand Down

0 comments on commit 25c46a4

Please sign in to comment.