-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --config (-c) flag to set a path to a valid config file via comma…
…nd line
- Loading branch information
Showing
4 changed files
with
106 additions
and
29 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
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,49 @@ | ||
package app | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/urfave/cli/v2" | ||
"github.com/xEtarusx/xplane-gateway-downloader/config" | ||
"log" | ||
"os" | ||
) | ||
|
||
type Action struct { | ||
} | ||
|
||
func (a *Action) Process(c *cli.Context, callback func(c *cli.Context) error) error { | ||
configFileLocation := c.String("config") | ||
|
||
// Config file not found | ||
if _, err := os.Stat(configFileLocation); errors.Is(err, os.ErrNotExist) { | ||
fmt.Printf("Config file '%s' not found. Download the default config.json from the project and put it next to the binary.", configFileLocation) | ||
return nil | ||
} | ||
|
||
// Load config.json | ||
cfg, err := config.LoadConfig(configFileLocation) | ||
if err != nil { | ||
log.Println(err) | ||
return nil | ||
} | ||
|
||
// Save config.json content into GlobalConfig | ||
config.GlobalConfig = cfg | ||
|
||
// Call the callback function for all logic | ||
err = callback(c) | ||
if err != nil { | ||
log.Println(err) | ||
return nil | ||
} | ||
|
||
// Save GlobalConfig back into config.json | ||
err = config.SaveConfig(configFileLocation) | ||
if err != nil { | ||
log.Println(err) | ||
return nil | ||
} | ||
|
||
return nil | ||
} |
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