Skip to content

Commit

Permalink
Merge pull request #3 from HappyTobi/fix_bugs
Browse files Browse the repository at this point in the history
Update some small stuff
  • Loading branch information
HappyTobi authored Jun 6, 2023
2 parents ac97a51 + 8c964e0 commit 7fe8541
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The cli tool brings the http api to the terminal.
| Command | Description |
| --- | --- |
| `warp info` | Get information about the warp charger |
| `warp info version` | Get the version of the warp charger |
| `warp info version warp` | Get the version of the warp charger |
| `warp info version update` | Check if an warp charger update is available |
| `warp info name` | Get the name of the warp charger |
| `warp infor display-name` | Get the display name of the warp charger |
Expand Down
18 changes: 14 additions & 4 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@ func InfoCmd() *cobra.Command {

func versionCmd() *cobra.Command {
version := &cobra.Command{
Use: "version",
Short: "Print Warp Charger version",
RunE: info.Version,
PreRunE: ValidateOutputformat,
Use: "version",
Short: "Show Warp Charger version or check for updates",
Long: "Show Warp Charger version that is currently installed at the Warp Charger. The other option is to check for an update",
}

version.AddCommand(updateCmd())
version.AddCommand(warpmVersionCmd())

return version
}

func warpmVersionCmd() *cobra.Command {
warpVersion := &cobra.Command{
Use: "warp",
Short: "Print Warp Charger version",
RunE: info.Version,
PreRunE: ValidateOutputformat,
}
return warpVersion
}

func updateCmd() *cobra.Command {
return &cobra.Command{
Use: "update",
Expand Down
17 changes: 14 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/spf13/viper"
)

const (
oldConfig = ".warp.yaml"
configFileName = "warp.yaml"
)

func Root() *cobra.Command {
root := &cobra.Command{
Use: "warp",
Expand Down Expand Up @@ -41,16 +46,18 @@ func initConfig() {
cobra.CheckErr(err)

configPath := filepath.Join(home, ".config", "warp")
configFilePath := filepath.Join(configPath, configFileName)
configFilePathLegacy := filepath.Join(home, oldConfig)

migrated := false
if _, err := os.Stat(filepath.Join(home, ".warp.yaml")); !os.IsNotExist(err) {
if _, err := os.Stat(configFilePathLegacy); !os.IsNotExist(err) {
fmt.Println("Configurations file will me moved and updated to new format")
_ = os.MkdirAll(configPath, os.ModePerm)
if err := os.Rename(filepath.Join(home, "warp.yaml"), filepath.Join(configPath, "warp.yaml")); err != nil {
if err := os.Rename(configFilePathLegacy, configFilePath); err != nil {
fmt.Println("Error while moving config file")
os.Exit(1)
}
os.Remove(filepath.Join(home, ".warp.yaml"))
os.Remove(configFilePathLegacy)
migrated = true
}

Expand Down Expand Up @@ -86,6 +93,10 @@ func initConfig() {
os.Exit(1)
}

if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
os.WriteFile(configFilePath, []byte{}, 0644)
}

if err := viper.WriteConfig(); err != nil {
fmt.Print(err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/renderer/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (pR *pdfRenderer) Render(filepath string, render func(timeZone *time.Locati

pdf.Row(5, func() {
pdf.Col(4, func() {
pdf.Text(fmt.Sprintf("%s %s", pR.settings.Settings.Postcode, pR.settings.Settings.Street), props.Text{
pdf.Text(fmt.Sprintf("%s %s", pR.settings.Settings.Postcode, pR.settings.Settings.City), props.Text{
Align: consts.Left,
})
})
Expand Down

0 comments on commit 7fe8541

Please sign in to comment.