Skip to content

Commit

Permalink
feat: Restructure commands
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 10, 2022
1 parent 5a6c4d1 commit 569e6f9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
22 changes: 22 additions & 0 deletions account-api/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package account_api

import (
"fmt"
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -23,7 +25,27 @@ func (c Client) NewAuthenticatedRequest(method, path string, body io.Reader) (*h
r.Header.Set("x-shopware-token", c.token.Token)

return r, nil
}

func (c Client) doRequest(request *http.Request) ([]byte, error) {
resp, err := http.DefaultClient.Do(request)

if err != nil {
return nil, err
}

defer resp.Body.Close()

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("doRequest: %v", err)
}

if resp.StatusCode != 200 {
return nil, fmt.Errorf(string(data))
}

return data, nil
}

func (c Client) GetActiveCompanyId() int {
Expand Down
14 changes: 14 additions & 0 deletions cmd/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/spf13/cobra"
)

var accountRootCmd = &cobra.Command{
Use: "account",
Short: "Manage your Shopware Account",
}

func init() {
rootCmd.AddCommand(accountRootCmd)
}
14 changes: 14 additions & 0 deletions cmd/account_company.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/spf13/cobra"
)

var accountCompanyRootCmd = &cobra.Command{
Use: "company",
Short: "Manage your Shopware company",
}

func init() {
accountRootCmd.AddCommand(accountCompanyRootCmd)
}
4 changes: 2 additions & 2 deletions cmd/account_company_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var accountCompanyListCmd = &cobra.Command{
Use: "account:company:list",
Use: "list",
Short: "Lists all available company for your Account",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -26,5 +26,5 @@ var accountCompanyListCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(accountCompanyListCmd)
accountCompanyRootCmd.AddCommand(accountCompanyListCmd)
}
4 changes: 2 additions & 2 deletions cmd/account_company_use.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var accountCompanyUseCmd = &cobra.Command{
Use: "account:company:use [companyId]",
Use: "use [companyId]",
Short: "Use another company for your Account",
Args: cobra.MinimumNArgs(1),
Long: ``,
Expand Down Expand Up @@ -41,5 +41,5 @@ var accountCompanyUseCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(accountCompanyUseCmd)
accountCompanyRootCmd.AddCommand(accountCompanyUseCmd)
}
4 changes: 2 additions & 2 deletions cmd/account_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var loginCmd = &cobra.Command{
Use: "account:login",
Use: "login",
Short: "Login into your Shopware Account",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -72,7 +72,7 @@ var loginCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(loginCmd)
accountRootCmd.AddCommand(loginCmd)
}

func askUserForEmailAndPassword() (string, string) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/account_logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var logoutCmd = &cobra.Command{
Use: "account:logout",
Use: "logout",
Short: "Logout from Shopware Account",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -27,5 +27,5 @@ var logoutCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(logoutCmd)
accountRootCmd.AddCommand(logoutCmd)
}

0 comments on commit 569e6f9

Please sign in to comment.