-
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.
Added all status code definitions and updated root command
Signed-off-by: valentine <[email protected]>
- Loading branch information
valentine
committed
Jul 6, 2022
1 parent
698467b
commit abf65ee
Showing
6 changed files
with
748 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/valxntine/whattp/internal/codes" | ||
) | ||
|
||
var border = "##########################################################################################" | ||
var blankBorder = "# #" | ||
var rootCmd = &cobra.Command{ | ||
Use: "whattp <status_code>", | ||
Short: "whattp is a CLI tool to find out what that pesky response code means.", | ||
Long: `A minimal, offline-ready http response code explorer built with love by valxntine.`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
statuses := codes.NewStatusCodes() | ||
v, ok := statuses[args[0]] | ||
if !ok { | ||
fmt.Fprintln(os.Stdout, center(border, 50)) | ||
fmt.Fprintln(os.Stdout, center(blankBorder, 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" _____________________________ "), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder("< are you sure thats...right? >"), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" ----------------------------- "), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder("\\ ^__^"), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" \\ (oo)\\_______"), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" (__)\\ )\\/\\"), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" ||----w |"), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(" || ||"), 50)) | ||
fmt.Fprintln(os.Stdout, center(blankBorder, 50)) | ||
fmt.Fprintln(os.Stdout, center(border, 50)) | ||
} else { | ||
fmt.Fprintln(os.Stdout, center(border, 50)) | ||
fmt.Fprintln(os.Stdout, center(blankBorder, 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineOne), 50)) | ||
fmt.Fprintln(os.Stdout, center(blankBorder, 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineTwo), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineThree), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineFour), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineFive), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineSix), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineSeven), 50)) | ||
fmt.Fprintln(os.Stdout, center(addBorder(v.LineEight), 50)) | ||
fmt.Fprintln(os.Stdout, center(blankBorder, 50)) | ||
fmt.Fprintln(os.Stdout, center(border, 50)) | ||
|
||
} | ||
}, | ||
} | ||
|
||
func center(s string, w int) string { | ||
return fmt.Sprintf("%*s", -w, fmt.Sprintf("%*s", (w+len(s))/2, s)) | ||
} | ||
|
||
func calculateGaps(s string) (int, int) { | ||
if len(s)%2 == 0 { | ||
return ((90 - len(s)) / 2) - 1, ((90 - len(s)) / 2) - 1 | ||
} | ||
return ((89 - len(s)) / 2) - 1, ((89 - len(s)) / 2) | ||
} | ||
|
||
func addBorder(s string) string { | ||
leftGap, rightGap := calculateGaps(s) | ||
borderChar := "#" | ||
return fmt.Sprint(borderChar + strings.Repeat(" ", leftGap) + s + strings.Repeat(" ", rightGap) + borderChar) | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.