Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
secman cli: change os exiting code to 2 instead of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Apr 13, 2022
1 parent 51ef0b5 commit a3b4d1f
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 39 deletions.
10 changes: 5 additions & 5 deletions api/get-latest.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package api

import (
"os"
"fmt"
"time"
"net/http"
"io/ioutil"
"net/http"
"os"
"time"

"github.com/briandowns/spinner"
httpClient "github.com/abdfnx/resto/client"
"github.com/briandowns/spinner"
)

func GetLatest(product string, isChecker bool) string {
Expand All @@ -28,7 +28,7 @@ func GetLatest(product string, isChecker bool) string {

if err != nil {
fmt.Printf("Error creating request: %s \n", err.Error())
os.Exit(0)
os.Exit(2)
}

suffix := " 🔍 Requesting..."
Expand Down
8 changes: 4 additions & 4 deletions cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func LoginCMD() *cobra.Command{
} else {
if err := tea.NewProgram(login.Login()).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func LogoutCMD() *cobra.Command {
} else {
if err := tea.NewProgram(logout.Logout()).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}
}

Expand All @@ -128,7 +128,7 @@ var CreateCMD = &cobra.Command{
if err != nil {
fmt.Printf("could not open browser: %s\n", err)

os.Exit(1)
os.Exit(2)
}

return nil
Expand All @@ -142,7 +142,7 @@ var RefreshCMD = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
if err := tea.NewProgram(refresh.Refresh()).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func DeleteCMD() *cobra.Command {

if err := tea.NewProgram(delete.Delete(&PwOpts)).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions cli/docs.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cli

import (
"os"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/scmn-dev/browser"
"github.com/spf13/cobra"
)

var DocsCMD = &cobra.Command{
Expand All @@ -18,7 +18,7 @@ var DocsCMD = &cobra.Command{
if err != nil {
fmt.Printf("could not open browser: %s\n", err)

os.Exit(1)
os.Exit(2)
}
},
}
14 changes: 7 additions & 7 deletions cli/encrypt.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cli

import (
"io"
"os"
"fmt"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"crypto/sha512"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -23,7 +23,7 @@ func EncryptCMD() *cobra.Command {
if EncryptOpts.AES {
if len(EncryptOpts.AESKey) < 32 {
fmt.Println("AES key must be 32 characters or longer.")
os.Exit(1)
os.Exit(2)
} else {
text := []byte(args[0])
key := []byte(EncryptOpts.AESKey)
Expand Down Expand Up @@ -60,7 +60,7 @@ func EncryptCMD() *cobra.Command {
fmt.Printf("%x\n", hash)
} else {
fmt.Println("No encryption algorithm selected.")
os.Exit(1)
os.Exit(2)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cli/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func InsertCMD() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
if err := tea.NewProgram(insert.Insert(&PwOpts)).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ListCMD() *cobra.Command {

fmt.Println(lipgloss.NewStyle().PaddingLeft(2).SetString(constants.Logo("Secman Lister") + st.Wrap.Render(head + body)).String())

os.Exit(0)
os.Exit(2)
}

fmt.Println(errout)
Expand All @@ -51,7 +51,7 @@ func ListCMD() *cobra.Command {
} else {
if err := tea.NewProgram(lister.Lister(), tea.WithAltScreen()).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(1)
os.Exit(2)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cli/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func ReadCMD() *cobra.Command {

if err != nil {
fmt.Println(errout)
os.Exit(1)
os.Exit(2)
} else {
fmt.Print("\n" + out)
}
} else {
if err := tea.NewProgram(read.Read(&PwOpts)).Start(); err != nil {
fmt.Printf("could not start program: %s\n", err)
os.Exit(0)
os.Exit(2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m model) View() string {
if user == "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(constants.Logo("Secman Auth") + m.styles.Error.Render("\n\nYou are not logged in. Please use ") + m.styles.Subtle.Render("`secman auth login`") + m.styles.Error.Render(" command to login.")))

os.Exit(0)
os.Exit(2)

return ""
} else {
Expand All @@ -142,7 +142,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (m model) View() string {
if user == "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(constants.Logo("Secman Auth") + m.styles.Error.Render("\n\nYou are not logged in. Please use ") + m.styles.Subtle.Render("`secman auth login`") + m.styles.Error.Render(" command to login.")))

os.Exit(0)
os.Exit(2)

return ""
} else {
Expand All @@ -208,7 +208,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pipe/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/pipe/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if ok {
if err := tea.NewProgram(editor.Editor(m.pwType, string(i), m.password)).Start(); err != nil {
fmt.Printf("could not start editor: %s\n", err)
os.Exit(1)
os.Exit(2)
}
}

Expand Down Expand Up @@ -93,6 +93,6 @@ func Edit(o *options.PasswordsOptions) {

if err := tea.NewProgram(m).Start(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
os.Exit(2)
}
}
2 changes: 1 addition & 1 deletion pkg/pipe/edit/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pipe/insert/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (m model) View() string {

if m.message != "" {
fmt.Println(lipgloss.NewStyle().Padding(0, 2).SetString(m.message).String())
os.Exit(0)
os.Exit(2)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/pipe/lister/passwords.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func readPasswords(p string) []list.Item {
fmt.Println(err)
fmt.Println(errout)

os.Exit(1)
os.Exit(2)
}

s.Stop()
Expand All @@ -60,7 +60,7 @@ func readPasswords(p string) []list.Item {

fmt.Println(lipgloss.NewStyle().PaddingLeft(2).SetString(constants.Logo("Secman Lister") + st.Wrap.Render(head + body)).String())

os.Exit(0)
os.Exit(2)
}

viper.SetConfigType("yaml")
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipe/read/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Read(o *options.PasswordsOptions) model {
if err != nil {
fmt.Println(err)
fmt.Println(errout)
os.Exit(0)
os.Exit(2)
}

s.Stop()
Expand All @@ -69,7 +69,7 @@ func Read(o *options.PasswordsOptions) model {

fmt.Println(lipgloss.NewStyle().PaddingLeft(2).SetString(constants.Logo("Secman Reader") + m.styles.Wrap.Render(head + body)).String())

os.Exit(0)
os.Exit(2)
} else if o.Logins {
title := gjson.Get(out, "title")
url := gjson.Get(out, "url")
Expand Down

0 comments on commit a3b4d1f

Please sign in to comment.