-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It opens the documentation you request in a browser. aspect docs -> open docs.bazel.build aspect docs query-how-to -> https://docs.bazel.build/versions/main/query-how-to.html aspect docs rules_nodejs -> https://docs.aspect.dev/rules_nodejs
- Loading branch information
Showing
13 changed files
with
163 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "docs", | ||
srcs = ["docs.go"], | ||
importpath = "aspect.build/cli/cmd/aspect/docs", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/aspect/docs", | ||
"//pkg/ioutils", | ||
"@com_github_spf13_cobra//:cobra", | ||
], | ||
) |
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,33 @@ | ||
/* | ||
Copyright © 2021 Aspect Build Systems | ||
Not licensed for re-use | ||
*/ | ||
|
||
package docs | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"aspect.build/cli/pkg/aspect/docs" | ||
"aspect.build/cli/pkg/ioutils" | ||
) | ||
|
||
func NewDefaultDocsCmd() *cobra.Command { | ||
return NewDocsCmd(ioutils.DefaultStreams) | ||
} | ||
|
||
func NewDocsCmd(streams ioutils.Streams) *cobra.Command { | ||
v := docs.New(streams) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "docs", | ||
Short: "Open documentation in the browser", | ||
Long: `Given a selected topic, open the relevant API docs in a browser window. | ||
The mechanism of choosing the browser to open is documented at https://github.com/pkg/browser | ||
By default, opens docs.bazel.build`, | ||
RunE: v.Run, | ||
} | ||
|
||
return cmd | ||
} |
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,32 @@ | ||
## aspect docs | ||
|
||
Open documentation in the browser | ||
|
||
### Synopsis | ||
|
||
Given a selected topic, open the relevant API docs in a browser window. | ||
The mechanism of choosing the browser to open is documented at https://github.com/pkg/browser | ||
By default, opens docs.bazel.build | ||
|
||
``` | ||
aspect docs [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for docs | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.aspect.yaml) | ||
--interactive Interactive mode (e.g. prompts for user input) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [aspect](aspect.md) - Aspect.build bazel wrapper | ||
|
||
###### Auto generated by spf13/cobra on 6-Sep-2021 |
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,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "docs", | ||
srcs = ["docs.go"], | ||
importpath = "aspect.build/cli/pkg/aspect/docs", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/ioutils", | ||
"@com_github_pkg_browser//:browser", | ||
"@com_github_spf13_cobra//:cobra", | ||
], | ||
) |
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,49 @@ | ||
/* | ||
Copyright © 2021 Aspect Build Systems Inc | ||
Not licensed for re-use. | ||
*/ | ||
|
||
package docs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"aspect.build/cli/pkg/ioutils" | ||
"github.com/pkg/browser" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Docs struct { | ||
ioutils.Streams | ||
} | ||
|
||
func New(streams ioutils.Streams) *Docs { | ||
return &Docs{ | ||
Streams: streams, | ||
} | ||
} | ||
|
||
func (v *Docs) Run(_ *cobra.Command, args []string) error { | ||
// TODO: we should open the browser to the bazel version matching what is running | ||
dest := "https://docs.bazel.build" | ||
|
||
// Detect requests for docs on rules, which we host | ||
if len(args) == 1 { | ||
if strings.HasPrefix(args[0], "rules_") { | ||
dest = fmt.Sprintf("https://docs.aspect.dev/%s", args[0]) | ||
} else { | ||
dest = fmt.Sprintf("https://docs.bazel.build/versions/main/%s.html", args[0]) | ||
} | ||
} | ||
// TODO: a way to lookup whatever the user typed after "docs" using docs.aspect.dev search | ||
// as far as I can tell, Algolia doesn't provide a way to render results on a dedicated search page | ||
// so I can't find a way to hyperlink to a search result. | ||
if err := browser.OpenURL(dest); err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to open link in the browser: %v\n", err) | ||
} | ||
|
||
return nil | ||
} |