-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes from testing the actual cli
- Loading branch information
Showing
10 changed files
with
125 additions
and
31 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
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,21 @@ | ||
package etc | ||
|
||
import "strings" | ||
|
||
func ArgsToFlagsMap(args []string) map[string]string { | ||
out := make(map[string]string) | ||
for idx, arg := range args { | ||
if isFlagKey(arg) { | ||
key := strings.TrimPrefix(arg, "-") | ||
out[key] = args[idx+1] | ||
} | ||
} | ||
return out | ||
} | ||
|
||
func isFlagKey(arg string) bool { | ||
if strings.HasPrefix(arg, "-") { | ||
return true | ||
} | ||
return false | ||
} |
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 |
---|---|---|
@@ -1,23 +1,36 @@ | ||
package etc | ||
|
||
import "fmt" | ||
|
||
func PrintHeader(message string, args ...interface{}) { | ||
fmt.Printf(message, args...) | ||
} | ||
import ( | ||
"encoding/json" | ||
"github.com/fatih/color" | ||
) | ||
|
||
func PrintInfo(message string, args ...interface{}) { | ||
fmt.Printf(message, args...) | ||
c := color.New(color.FgCyan) | ||
_, _ = c.Printf(message, args...) | ||
} | ||
|
||
func PrintResponse(message string, args ...interface{}) { | ||
fmt.Printf(message, args...) | ||
c := color.New(color.FgYellow).Add(color.Italic) | ||
_, _ = c.Printf(message, args...) | ||
} | ||
|
||
func PrettyPrintJson(m map[string]interface{}) { | ||
bytes, err := json.MarshalIndent(m, "", " ") | ||
if err != nil { | ||
PrintError(err.Error()) | ||
return | ||
} | ||
|
||
PrintResponse("%s\n", string(bytes)) | ||
} | ||
|
||
func PrintError(message string, args ...interface{}) { | ||
fmt.Printf(message, args...) | ||
c := color.New(color.FgRed).Add(color.Bold) | ||
_, _ = c.Printf(message, args...) | ||
} | ||
|
||
func PrintSuccess(message string, args ...interface{}) { | ||
fmt.Printf(message, args...) | ||
c := color.New(color.FgGreen).Add(color.Bold) | ||
_, _ = c.Printf(message, args...) | ||
} |
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,36 @@ | ||
package packman | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func ReadFlags() map[string]string { | ||
var out map[string]string | ||
path := os.Args[1] | ||
flagsContent, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = json.Unmarshal(flagsContent, &out) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return out | ||
} | ||
|
||
func WriteReply(model interface{}) { | ||
bytes, err := json.Marshal(model) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
path := os.Args[2] | ||
err = ioutil.WriteFile(path, bytes, os.ModePerm) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |