Skip to content

Commit 90ac1e1

Browse files
committed
add code support
1 parent 4452fd1 commit 90ac1e1

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

Readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ sicher edit
5555

5656
**_Optional flags:_**
5757

58-
| flag | description | default | options |
59-
| ------- | ----------------------------------------------- | ------- | -------------- |
60-
| -env | set the environment name | dev | |
61-
| -path | set the path to the credentials file | . | |
62-
| -editor | set the editor to use | vim | vim, nano, vi |
63-
| -style | set the style of the decrypted credentials file | dotenv | dotenv or yaml |
64-
65-
This will create a temporary file, decrypt the credentials into it, and open it in your editor. The editor defaults to `vim`, but can be also set to `nano` or `vi` with the `-editor` flag. The temporary file is destroyed after each save, and the encrypted credentials file is updated with the new content.
58+
| flag | description | default | options |
59+
| ------- | ----------------------------------------------- | ------- | ------------------- |
60+
| -env | set the environment name | dev | |
61+
| -path | set the path to the credentials file | . | |
62+
| -editor | set the editor to use | vim | vim, nano, vi, code |
63+
| -style | set the style of the decrypted credentials file | dotenv | dotenv or yaml |
64+
65+
This will create a temporary file, decrypt the credentials into it, and open it in your editor. The editor defaults to `vim`, but can be also set to other editors with the `-editor` flag. The temporary file is destroyed after each save, and the encrypted credentials file is updated with the new content.
6666

6767
Then in your app, you can use the `sicher` library to load the credentials:
6868

cli/sicher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
flag.StringVar(&pathFlag, "path", ".", "Path to the project")
3333
flag.StringVar(&envFlag, "env", "dev", "Environment to use")
3434
flag.StringVar(&styleFlag, "style", string(sicher.DefaultEnvStyle), "Env file style. Valid values are dotenv and yaml")
35-
flag.StringVar(&editorFlag, "editor", "vim", "Select editor. vim | vi | nano")
35+
flag.StringVar(&editorFlag, "editor", "vim", "Select editor. vim | vi | nano | code")
3636
flag.StringVar(&gitignorePathFlag, "gitignore", ".", "Path to the gitignore file")
3737

3838
flag.ErrHelp = errors.New(errHelp)

dev.enc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3eee81c9d49368bf2afed13a2fcdf2ad41a5e5f6d2f0b2195174e30cc25259d44c43==--==cf4b4f760ac9e5700b049361
1+
d23c446cbf6dda61365112d6cd815426e433a23c07aaa562d84bf7c4527adeac4a8966358df27d2fb8d2b43cc548240f6a1169a45ea477742d97f6ff==--==7007112fa552cbfe5457b407

sicher.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,15 @@ func (s *sicher) Edit(editor ...string) error {
148148
editorName = "vim"
149149
}
150150

151-
match, _ := regexp.MatchString("^(nano|vim|vi|)$", editorName)
151+
match, _ := regexp.MatchString("^(nano|vim|vi|code|)$", editorName)
152152
if !match {
153-
return fmt.Errorf("invalid Command: Select one of vim, vi, or nano as editor, or leave as empty")
153+
return fmt.Errorf("invalid Command: Select one of vim, vi, code or nano as editor, or leave as empty")
154+
}
155+
156+
// waitOpt is needed to enable vscode to wait for the editor to close before continuing
157+
var waitOpt string
158+
if editorName == "code" {
159+
waitOpt = "--wait"
154160
}
155161

156162
// read the encryption key
@@ -202,7 +208,7 @@ func (s *sicher) Edit(editor ...string) error {
202208
}
203209

204210
//open decrypted file with editor
205-
cmd := execCmd(editorName, filePath)
211+
cmd := execCmd(editorName, waitOpt, filePath)
206212
cmd.Stdin = stdIn
207213
cmd.Stdout = stdOut
208214
cmd.Stderr = stdErr

0 commit comments

Comments
 (0)