-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructure otti package, improve integrated help
- Loading branch information
Showing
14 changed files
with
303 additions
and
157 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
File renamed without changes.
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,47 @@ | ||
// SPDX-FileCopyrightText: 2023 Christoph Mewes | ||
// SPDX-License-Identifier: MIT | ||
|
||
package help | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/pflag" | ||
"go.xrstf.de/otto/cmd/otti/types" | ||
"go.xrstf.de/otto/cmd/otti/util" | ||
"go.xrstf.de/otto/docs" | ||
) | ||
|
||
//go:embed help.md | ||
var helpText string | ||
|
||
func Run(opts *types.Options, args []string) error { | ||
helpTopics := docs.Topics() | ||
|
||
// do not show function docs for "--help help if" | ||
if !opts.ShowHelp && len(args) == 2 && args[0] == "help" { | ||
rendered, err := util.RenderHelpTopic(helpTopics, args[1], 0) | ||
if err == nil { | ||
fmt.Println(rendered) | ||
return nil | ||
} | ||
|
||
fmt.Printf("Error: %v\n", err) | ||
fmt.Println() | ||
fmt.Println("The following topics are available:") | ||
fmt.Println() | ||
fmt.Println(util.RenderHelpTopics(helpTopics, 0)) | ||
|
||
return nil | ||
} | ||
|
||
fmt.Println(util.RenderMarkdown(strings.TrimSpace(helpText), 0)) | ||
fmt.Println(util.RenderHelpTopics(helpTopics, 0)) | ||
fmt.Println() | ||
|
||
pflag.Usage() | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# The Otto interpreter :) | ||
|
||
Otti is a command line interpreter for the Otto programming language. Otti can | ||
read multiple JSON/YAML files and then apply JSON paths or scripts to them. For | ||
quicker development, an interactive REPL is also available. | ||
|
||
## Modes | ||
|
||
Otti can run in one of two modes: | ||
|
||
* **Interactive Mode** is enabled by passing `--interactive` (or `-i`). This will | ||
start a REPL session where Otto scripts are read from stdin and evaluated | ||
against the loaded files. | ||
* **Script Mode** is used the an Otto script is passed either as the first | ||
argument or read from a file defined by `--script`. In this mode Otti will | ||
run all statements from the script and print the resulting value, then it exits. | ||
|
||
Examples: | ||
|
||
* `otti '.foo' myfile.json` | ||
* `otti '(set .foo "bar") (set .users 42) .' myfile.json` | ||
* `otti --script convert.otto myfile.json` | ||
|
||
## File Handling | ||
|
||
The first loaded file is known as the "document". Its content is available via | ||
path expressions like `.foo[0]`. All loaded files are also available via the | ||
`$files` variable (i.e. `.` is the same as `$files[0]` for reading, but when | ||
writing data, there is a difference between both notations; refer to the docs | ||
for `set` for more information). | ||
|
||
## Help | ||
|
||
Help is available by using `help` as the first argument to Otto. This can be | ||
followed by a topic, like `help if`. |
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,21 @@ | ||
# Welcome to the Otto interpreter :) | ||
|
||
You can enter one of | ||
|
||
* A path expression, like `.foo` or `.foo[0].bar` to access the global document. | ||
* An expression like (+ .foo 42) to compute data by functions; see the topics | ||
below or the Otto website for a complete list of available functions. | ||
* A scalar JSON value, like `3` or `[1 2 3]`, which will simply return that | ||
exact value with no further side effects. Not super useful usually. | ||
|
||
## Commands | ||
|
||
Additionally, the following commands can be used: | ||
|
||
* help – Show this help text. | ||
* help TOPIC – Show help for a specific topic. | ||
* exit – Exit Otti immediately. | ||
|
||
## Help Topics | ||
|
||
The following topics are available and can be accessed using `help TOPIC`: |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.