Compare commits
2 Commits
56cec1580a
...
fce1ab6c02
Author | SHA1 | Date |
---|---|---|
decentral1se | fce1ab6c02 | |
decentral1se | 381de28e83 |
|
@ -94,6 +94,28 @@ func AppsFSIsLatest() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadApps() (Apps, error) {
|
||||||
|
apps := make(Apps)
|
||||||
|
|
||||||
|
appsFSIsLatest, err := AppsFSIsLatest()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !appsFSIsLatest {
|
||||||
|
if err := ReadAppsWeb(&apps); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return apps, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ReadAppsFS(&apps); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return apps, nil
|
||||||
|
}
|
||||||
|
|
||||||
func ReadAppsFS(target interface{}) error {
|
func ReadAppsFS(target interface{}) error {
|
||||||
appsJsonFS, err := ioutil.ReadFile(config.APPS_JSON)
|
appsJsonFS, err := ioutil.ReadFile(config.APPS_JSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,36 +127,21 @@ func ReadAppsFS(target interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadAppsWeb() (Apps, error) {
|
func ReadAppsWeb(target interface{}) error {
|
||||||
apps := make(Apps)
|
if err := readJson(AppsUrl, &target); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
appsFSIsLatest, err := AppsFSIsLatest()
|
appsJson, err := json.MarshalIndent(target, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !appsFSIsLatest {
|
if err := ioutil.WriteFile(config.APPS_JSON, appsJson, 0644); err != nil {
|
||||||
if err := readJson(AppsUrl, &apps); err != nil {
|
return err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
appsJson, err := json.MarshalIndent(apps, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ioutil.WriteFile(config.APPS_JSON, appsJson, 0644); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return apps, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ReadAppsFS(&apps); err != nil {
|
return nil
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return apps, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortByAppName(apps Apps) []string {
|
func SortByAppName(apps Apps) []string {
|
||||||
|
@ -150,16 +157,16 @@ var recipeListCommand = &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
appSpecs, err := ReadAppsWeb()
|
apps, err := ReadApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err.Error())
|
logrus.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
tableCol := []string{"Name", "Category", "Status"}
|
tableCol := []string{"Name", "Category", "Status"}
|
||||||
table := createTable(tableCol)
|
table := createTable(tableCol)
|
||||||
for _, appName := range SortByAppName(appSpecs) {
|
for _, name := range SortByAppName(apps) {
|
||||||
appSpec := appSpecs[appName]
|
app := apps[name]
|
||||||
status := fmt.Sprintf("%v", appSpec.Features.Status)
|
status := fmt.Sprintf("%v", app.Features.Status)
|
||||||
tableRow := []string{appSpec.Name, appSpec.Category, status}
|
tableRow := []string{app.Name, app.Category, status}
|
||||||
table.Append(tableRow)
|
table.Append(tableRow)
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
Loading…
Reference in New Issue