Skip to content

Commit

Permalink
(cgi-ctl): add update manifest command
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Jun 17, 2020
1 parent 1c328e4 commit 84ba109
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmd/cgi-ctl/cmd_update_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"github.com/reddec/trusted-cgi/cmd/internal"
internal2 "github.com/reddec/trusted-cgi/internal"
"log"
"os"
"path/filepath"
)

type updateManifest struct {
remoteLink
UID string `short:"o" long:"uid" env:"UID" description:"Lambda UID (if empty - dirname of input will be used)"`
}

func (cmd *updateManifest) Execute(args []string) error {
ctx, closer := internal.SignalContext()
defer closer()
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("detect work dir: %w", err)
}
if cmd.UID == "" {
cmd.UID = filepath.Base(wd)
}
log.Println("lambda", cmd.UID)
log.Println("login...")
token, err := cmd.Token(ctx)
if err != nil {
return fmt.Errorf("login: %w", err)
}
log.Println("getting info...")
info, err := cmd.Lambdas().Info(ctx, token, cmd.UID)
if err != nil {
return fmt.Errorf("get info: %w", err)
}
log.Println("saving...")
err = info.Manifest.SaveAs(internal2.ManifestFile)
if err != nil {
return fmt.Errorf("update manifest file: %w", err)
}
log.Println("done")
return nil
}
3 changes: 3 additions & 0 deletions cmd/cgi-ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Config struct {
Do do `command:"do" description:"invoke actions (without actions it will print all available actions)"`
Create create `command:"create" description:"create new lambda on the remote platform and initialize local environment"`
Alias alias `command:"alias" description:"list, created or remove alias for the lambda"`
Update struct {
Manifest updateManifest `command:"manifest" description:"pull and save remote manifest file"`
} `command:"update" description:"update parts of the lambda"`
}

func main() {
Expand Down
28 changes: 28 additions & 0 deletions docs/cgi-ctl/update_manifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
layout: default
title: update manifest
parent: Control util
nav_order: 207
---

## update manifest

Pulls remote lambda manifest and saves it locally. Useful to update only the configuration, while
keeping files remotely unsynchronized with local environment.

```
Usage:
cgi-ctl [OPTIONS] update manifest [manifest-OPTIONS]
Help Options:
-h, --help Show this help message
[manifest command options]
-l, --login= Login name (default: admin) [$LOGIN]
-p, --password= Password (default: admin) [$PASSWORD]
-P, --ask-pass Get password from stdin [$ASK_PASS]
-u, --url= Trusted-CGI endpoint (default: http://127.0.0.1:3434/) [$URL]
--ghost Disable save credentials to user config dir [$GHOST]
--independent Disable read credentials from user config dir [$INDEPENDENT]
-o, --uid= Lambda UID (if empty - dirname of input will be used) [$UID]
```

0 comments on commit 84ba109

Please sign in to comment.