Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions cmd/commercemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"net/url"
"os/exec"
"runtime"
)

var cmCommand = &cobra.Command{
Expand All @@ -29,18 +27,7 @@ var cmCommand = &cobra.Command{
fmt.Printf("Don't know where Commerce Manager is for $EPCC_API_BASE_URL=%s \n", u)
return err
}

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", cmUrl).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", cmUrl).Start()
case "darwin":
err = exec.Command("open", cmUrl).Start()
default:
err = fmt.Errorf("unsupported platform")
}

err = OpenUrl(cmUrl)
if err != nil {
fmt.Println(err)
return err
Expand Down
15 changes: 14 additions & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ package cmd

import (
"fmt"
"github.com/elasticpath/epcc-cli/external/resources"
"github.com/spf13/cobra"
)

var docsCommand = &cobra.Command{
Use: "docs <resource>",
Short: "Opens up API documentation for the resource",
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("This function is not implemented")
if len(args) != 0 {
resource := resources.Resources[args[0]]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the resource doesn't exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
returning error as below
return fmt.Errorf("You must supply a valid resource type to the docs command")"

if len(resource.Docs) > 0 {
url := resource.Docs
err := OpenUrl(url)
if err != nil {
return nil
}
} else {
return fmt.Errorf("You must supply a valid resource type to the docs command")
}
}
return fmt.Errorf("You must supply a resource type to the docs command")
},
}
23 changes: 23 additions & 0 deletions cmd/share.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"
"os/exec"
"runtime"
)

func OpenUrl(cmUrl string) error {

switch runtime.GOOS {
case "linux":
exec.Command("xdg-open", cmUrl).Start()
case "windows":
exec.Command("rundll32", "url.dll,FileProtocolHandler", cmUrl).Start()
case "darwin":
exec.Command("open", cmUrl).Start()
default:
return fmt.Errorf("unsupported platform")
}

return nil
}