Skip to content
Snippets Groups Projects
Commit b25df246 authored by Florent Gluck's avatar Florent Gluck
Browse files

First usable version of nexush

parent bcf23f60
No related branches found
No related tags found
No related merge requests found
Showing
with 31 additions and 5 deletions
package cmd
import (
"strings"
u "nexus-client/utils"
)
type Command interface {
GetName() string
GetDesc() []string
PrintUsage()
Run(args []string) int // Returns 0 if the Command was successful.
}
func Help(commands []Command, indent string) {
padding := 20
for _, cmd := range commands {
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
cmdStr := indent+cmd.GetName()
u.PrintErr(cmdStr)
pad := strings.Repeat(" ", padding-len(cmd.GetName()))
for i, desc := range cmd.GetDesc() {
if i > 0 {
u.PrintErr(strings.Repeat(" ", len(cmdStr)))
}
u.PrintlnErr(pad+desc)
}
}
}
File moved
File moved
...@@ -39,7 +39,7 @@ func (cmd *Login)Run(args []string) int { ...@@ -39,7 +39,7 @@ func (cmd *Login)Run(args []string) int {
email := args[0] email := args[0]
pwd := args[1] pwd := args[1]
token, err := login(email, pwd) token, err := GetToken(email, pwd)
if err != nil { if err != nil {
u.PrintlnErr("Error: "+err.Error()) u.PrintlnErr("Error: "+err.Error())
return 1 return 1
...@@ -54,7 +54,7 @@ func (cmd *Login)Run(args []string) int { ...@@ -54,7 +54,7 @@ func (cmd *Login)Run(args []string) int {
// curl -X POST http://localhost:8000/login -H 'Content-Type: application/json' -d '{"email": "johndoe@nexus.org", "pwd":"pipomolo"}' // curl -X POST http://localhost:8000/login -H 'Content-Type: application/json' -d '{"email": "johndoe@nexus.org", "pwd":"pipomolo"}'
// Returns a jwt token if authentication was successful: // Returns a jwt token if authentication was successful:
// {"token":"<jwt token>"} // {"token":"<jwt token>"}
func login(user string, pwd string) (string, error) { func GetToken(user string, pwd string) (string, error) {
client := g.GetInstance().Client client := g.GetInstance().Client
host := g.GetInstance().Host host := g.GetInstance().Host
......
File moved
...@@ -40,7 +40,6 @@ func printUsage(c cmd.Command, action string) { ...@@ -40,7 +40,6 @@ func printUsage(c cmd.Command, action string) {
const usage string = `Any number of IDs or regexes can be specified. const usage string = `Any number of IDs or regexes can be specified.
The regex only matches the templates's name and is case-insensitive. The regex only matches the templates's name and is case-insensitive.
Regex examples: Regex examples:
"" -> matches any templates
"." -> matches any templates "." -> matches any templates
"bla" -> matches any templates containing "bla"` "bla" -> matches any templates containing "bla"`
u.PrintlnErr(usage) u.PrintlnErr(usage)
...@@ -76,7 +75,6 @@ func printFilteredTemplates(c cmd.Command, args []string, route string) int { ...@@ -76,7 +75,6 @@ func printFilteredTemplates(c cmd.Command, args []string, route string) int {
// - any regular expression (it applies to the template's name only) // - any regular expression (it applies to the template's name only)
// Remark: the matching is case-insensitive // Remark: the matching is case-insensitive
// Regular expression examples: // Regular expression examples:
// "" -> matches everything
// "." -> matches everything // "." -> matches everything
// "bla" -> matches any template name containing "bla" // "bla" -> matches any template name containing "bla"
func getFilteredTemplates(route string, patterns []string) ([]Template, error) { func getFilteredTemplates(route string, patterns []string) ([]Template, error) {
......
File moved
File moved
...@@ -45,7 +45,6 @@ func printRegexUsageDetails() { ...@@ -45,7 +45,6 @@ func printRegexUsageDetails() {
Any number of regexes can be specified. Any number of regexes can be specified.
The regex matches the user email, first name and last name and is case-insensitive. The regex matches the user email, first name and last name and is case-insensitive.
Regex examples: Regex examples:
"" -> matches any users
"." -> matches any users "." -> matches any users
"bla" -> matches any users containing "bla"` "bla" -> matches any users containing "bla"`
u.PrintlnErr(usage) u.PrintlnErr(usage)
......
File moved
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment