-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
34 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
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
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,66 @@ | ||
package root | ||
|
||
import ( | ||
"bytes" | ||
"github.com/spf13/cobra" | ||
"github.com/vulncheck-oss/cli/pkg/i18n" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_AuthCommand(t *testing.T) { | ||
actual, root := setRootActual("auth") | ||
root.SetArgs([]string{"auth"}) | ||
if err := root.Execute(); err != nil { | ||
t.Errorf("expected no error but got %v", err) | ||
} | ||
if strings.HasPrefix(i18n.C.AuthShort, actual.String()) { | ||
t.Errorf("expected %s but got %s", i18n.C.AuthShort, actual.String()) | ||
} | ||
} | ||
|
||
func Test_IndicesCommand(t *testing.T) { | ||
actual, root := setRootActual("indices") | ||
root.SetArgs([]string{"indices"}) | ||
if err := root.Execute(); err != nil { | ||
t.Errorf("expected no error but got %v", err) | ||
} | ||
if strings.HasPrefix(i18n.C.IndicesShort, actual.String()) { | ||
t.Errorf("expected %s but got %s", i18n.C.IndicesShort, actual.String()) | ||
} | ||
} | ||
|
||
func Test_IndexCommand(t *testing.T) { | ||
actual, root := setRootActual("index") | ||
root.SetArgs([]string{"index"}) | ||
if err := root.Execute(); err != nil { | ||
t.Errorf("expected no error but got %v", err) | ||
} | ||
if strings.HasPrefix(i18n.C.IndexShort, actual.String()) { | ||
t.Errorf("expected %s but got %s", i18n.C.IndexShort, actual.String()) | ||
} | ||
} | ||
|
||
func Test_BackupCommand(t *testing.T) { | ||
actual, root := setRootActual("backup") | ||
root.SetArgs([]string{"backup"}) | ||
if err := root.Execute(); err != nil { | ||
t.Errorf("expected no error but got %v", err) | ||
} | ||
if strings.HasPrefix(i18n.C.BackupShort, actual.String()) { | ||
t.Errorf("expected %s but got %s", i18n.C.BackupShort, actual.String()) | ||
} | ||
} | ||
|
||
func setRootActual(args ...string) (*bytes.Buffer, *cobra.Command) { | ||
actual := new(bytes.Buffer) | ||
root := NewCmdRoot() | ||
root.SetOut(actual) | ||
root.SetErr(actual) | ||
var argsArray []string | ||
for _, arg := range args { | ||
argsArray = append(argsArray, arg) | ||
} | ||
root.SetArgs(argsArray) | ||
return actual, root | ||
} |
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,86 @@ | ||
package i18n | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc/v2" | ||
) | ||
|
||
var lang = "en_US" | ||
|
||
type Copy struct { | ||
AboutInfo string | ||
InteractiveOnly string | ||
RootLong string | ||
|
||
AuthShort string | ||
IndicesShort string | ||
|
||
ListIndicesShort string | ||
ListIndicesSearch string | ||
ListIndicesFull string | ||
|
||
BrowseIndicesShort string | ||
BrowseIndicesSearch string | ||
BrowseIndicesFull string | ||
|
||
IndexShort string | ||
IndexListShort string | ||
IndexBrowseShort string | ||
|
||
BackupShort string | ||
BackupUrlShort string | ||
BackupDownloadShort string | ||
BackupDownloadInfo string | ||
BackupDownloadProgress string | ||
BackupDownloadComplete string | ||
|
||
ErrorNoToken string | ||
ErrorUnauthorized string | ||
|
||
ErrorIndexRequired string | ||
} | ||
|
||
var C Copy | ||
|
||
func Init() { | ||
C = En | ||
// TODO: after a 2nd language is added, detect the system language and set the lang variable accordingly | ||
// look at the LANG environment variable | ||
// bonus: missing keys of the 2nd language fallback to En | ||
} | ||
|
||
var En = Copy{ | ||
AboutInfo: heredoc.Doc(` | ||
The VulnCheck CLI is a command-line interface for the VulnCheck API | ||
For more information on our products, please visit https://vulncheck.com | ||
For API Documentation, please visit https://docs.vulncheck.com | ||
`), | ||
InteractiveOnly: "This command is interactive and cannot run in a CI environment, please try %s instead", | ||
RootLong: "Work seamlessly with the VulnCheck API.", | ||
|
||
AuthShort: "Authenticate vc with the VulnCheck portal", | ||
IndicesShort: "View indices", | ||
|
||
ListIndicesShort: "List indices", | ||
ListIndicesSearch: "Listing %d indices searching for \"%s\"", | ||
ListIndicesFull: "Listing %d indices", | ||
|
||
BrowseIndicesShort: "Browse indices", | ||
BrowseIndicesSearch: "Listing %d indices searching for \"%s\"", | ||
BrowseIndicesFull: "Listing %d indices", | ||
|
||
IndexShort: "Browse or list an index", | ||
IndexListShort: "List documents of a specified index", | ||
IndexBrowseShort: "Browse documents of an index interactively", | ||
|
||
BackupShort: "Download a backup of a specified index", | ||
BackupUrlShort: "Get the temporary signed URL of the backup of an index", | ||
BackupDownloadShort: "Download the backup of an index", | ||
|
||
BackupDownloadInfo: "Downloading backup of %s, created on %s", | ||
BackupDownloadProgress: "Downloading backup as %s", | ||
BackupDownloadComplete: "Backup downloaded successfully", | ||
|
||
ErrorNoToken: "No valid token found", | ||
ErrorUnauthorized: "Error: Unauthorized, Try authenticating with: vc auth login", | ||
ErrorIndexRequired: "index name is required", | ||
} |