-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Maahsome/BWCA-16/get-username
Add get username
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"bwca/common" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// getUsernameCmd represents the username command | ||
var getUsernameCmd = &cobra.Command{ | ||
Use: "username", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
itemID, _ := cmd.Flags().GetString("item-id") | ||
itemName, _ := cmd.Flags().GetString("item-name") | ||
if len(itemName) > 0 { | ||
itemID = getItemID(itemName) | ||
} | ||
if len(itemID) > 0 { | ||
getUsername(itemID) | ||
} else { | ||
common.Logger.Error("You must specify --item-id or --item-name") | ||
} | ||
}, | ||
} | ||
|
||
func getUsername(id string) { | ||
username, err := bwClient.GetUsername(id) | ||
if err != nil { | ||
common.Logger.Fatal("Failed to GetPassword") | ||
} | ||
fmt.Println(username) | ||
} | ||
|
||
func init() { | ||
getCmd.AddCommand(getUsernameCmd) | ||
|
||
getUsernameCmd.Flags().StringP("item-id", "i", "", "The ID of the item to fetch") | ||
getUsernameCmd.Flags().StringP("item-name", "n", "", "The name of the item to fetch, careful: name items wisely") | ||
} |