-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/dev-2817-replace-pathjoin-with-filep…
…athjoin-in-atmos-code
- Loading branch information
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