-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display CLI changelog with 'doppler changelog' command
This pulls the changelog from cli.doppler.com/changes.
- Loading branch information
1 parent
0040eec
commit 7c496ca
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright © 2020 Doppler <support@doppler.com> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/DopplerHQ/cli/pkg/http" | ||
"github.com/DopplerHQ/cli/pkg/models" | ||
"github.com/DopplerHQ/cli/pkg/printer" | ||
"github.com/DopplerHQ/cli/pkg/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var changelogCmd = &cobra.Command{ | ||
Use: "changelog", | ||
Short: "view the CLI's changelog", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
number := utils.GetIntFlag(cmd, "number", 16) | ||
jsonFlag := utils.OutputJSON | ||
|
||
response, apiError := http.GetChangelog() | ||
if !apiError.IsNil() { | ||
utils.HandleError(apiError.Unwrap(), apiError.Message) | ||
} | ||
|
||
changes := models.ParseChangeLog(response, number) | ||
printer.ChangeLog(changes, number, jsonFlag) | ||
}, | ||
} | ||
|
||
func init() { | ||
changelogCmd.Flags().IntP("number", "n", 3, "number of versions to show changes for") | ||
|
||
rootCmd.AddCommand(changelogCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright © 2020 Doppler <support@doppler.com> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package models | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/DopplerHQ/cli/pkg/utils" | ||
) | ||
|
||
// ChangeLog lists changes | ||
type ChangeLog struct { | ||
Changes []string `json:"changes"` | ||
} | ||
|
||
// ParseChangeLog parse change log | ||
func ParseChangeLog(response []byte, max int) map[string]ChangeLog { | ||
var releaseMap []map[string]interface{} | ||
if err := json.Unmarshal(response, &releaseMap); err != nil { | ||
utils.HandleError(err, "Unable to parse changelog") | ||
} | ||
|
||
changes := map[string]ChangeLog{} | ||
|
||
for i, release := range releaseMap { | ||
if i >= max { | ||
break | ||
} | ||
|
||
v := release["version"].(string) | ||
var list []string | ||
for _, change := range release["changes"].([]interface{}) { | ||
list = append(list, change.(string)) | ||
} | ||
|
||
changes[v] = ChangeLog{Changes: list} | ||
} | ||
|
||
return changes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters