-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pagination and searching to
atmos docs
command (#848)
* feat: add pagination and search to docs command * docs: update documentation with pagination settings * fix: cleanup documentation and capitalization --------- Co-authored-by: Andriy Knysh <[email protected]>
- Loading branch information
1 parent
c0e7054
commit 5681e54
Showing
4 changed files
with
65 additions
and
3 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
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,39 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
// DisplayDocs displays component documentation directly through the terminal or | ||
// through a pager (like less). The use of a pager is determined by the pagination value | ||
// set in the CLI Settings for Atmos | ||
func DisplayDocs(componentDocs string, usePager bool) error { | ||
if !usePager { | ||
fmt.Println(componentDocs) | ||
return nil | ||
} | ||
|
||
pagerCmd := os.Getenv("PAGER") | ||
if pagerCmd == "" { | ||
pagerCmd = "less -r" | ||
} | ||
|
||
args := strings.Fields(pagerCmd) | ||
if len(args) == 0 { | ||
return fmt.Errorf("invalid pager command") | ||
} | ||
|
||
cmd := exec.Command(args[0], args[1:]...) | ||
cmd.Stdin = strings.NewReader(componentDocs) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("failed to execute pager: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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