diff --git a/cli/commands/completion.go b/cli/commands/completion.go new file mode 100644 index 0000000000000..148f7c8e3bc32 --- /dev/null +++ b/cli/commands/completion.go @@ -0,0 +1,100 @@ +package commands + +import ( + "fmt" + "os" + + "github.com/hasura/graphql-engine/cli" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +const completionCmdExample = `# Bash + # Linux + # Add Bash completion file using: + $ sudo hasura completion bash --file=/etc/bash.completion.d/hasura + # Mac + # Install bash-completion using homebrew: + $ brew install bash-completion + # Add to your ~/.bash_profile: + if [ -f $(brew --prefix)/etc/bash_completion ]; then + . $(brew --prefix)/etc/bash_completion + fi + # Add the completion file: + $ sudo hasura completion bash --file=$(brew --prefix)/etc/bash_completion.d/hasura + # Windows (Git Bash) + # open git bash + $ mkdir -p ~/.bash_completion.d + # Add the completion file: + $ cd ~ && hasura completion bash --file=bash_completion.d/hasura + # Add the following to ~/.bash_profile + if [ -f ~/.bash_completion.d/hasura ]; then + . ~/.bash_completion.d/hasura + fi + # restart git bash + + # Zsh (using oh-my-zsh) + $ mkdir -p $HOME/.oh-my-zsh/completions + $ hasura completion zsh --file=$HOME/.oh-my-zsh/completions/_hasura + + # Reload the shell for the changes to take effect!` + +// NewCompletionCmd return the completion command. +func NewCompletionCmd(ec *cli.ExecutionContext) *cobra.Command { + opts := &completionOptions{ + EC: ec, + } + completionCmd := &cobra.Command{ + Use: "completion [shell]", + Short: "Generate auto completion code", + Args: cobra.ExactArgs(1), + Long: "Output shell completion code for the specified shell (bash or zsh)", + SilenceUsage: true, + Example: completionCmdExample, + PreRunE: func(cmd *cobra.Command, args []string) error { + ec.Viper = viper.New() + return ec.Prepare() + }, + RunE: func(cmd *cobra.Command, args []string) error { + opts.Shell = args[0] + opts.Cmd = cmd + return opts.run() + }, + } + + completionCmd.Flags().StringVar(&opts.File, "file", "", "file to which output has to be written") + completionCmd.MarkFlagFilename("file") + return completionCmd +} + +type completionOptions struct { + EC *cli.ExecutionContext + + Shell string + File string + Cmd *cobra.Command +} + +func (o *completionOptions) run() error { + var err error + switch o.Shell { + case "bash": + if o.File != "" { + err = o.Cmd.Root().GenBashCompletionFile(o.File) + } else { + err = o.Cmd.Root().GenBashCompletion(os.Stdout) + } + case "zsh": + if o.File != "" { + err = o.Cmd.Root().GenZshCompletionFile(o.File) + } else { + err = o.Cmd.Root().GenZshCompletion(os.Stdout) + } + default: + err = fmt.Errorf("Unknown shell: %s. Use bash or zsh", o.Shell) + } + if err != nil { + return err + } + return nil +} diff --git a/cli/commands/docs.go b/cli/commands/docs.go index 2a516a7f2eb29..68cc268493d48 100644 --- a/cli/commands/docs.go +++ b/cli/commands/docs.go @@ -1,9 +1,16 @@ package commands import ( + "bytes" + "fmt" + "io" "os" + "path/filepath" + "sort" + "strings" "github.com/hasura/graphql-engine/cli" + "github.com/hasura/graphql-engine/cli/assets" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" @@ -32,7 +39,7 @@ func NewDocsCmd(ec *cli.ExecutionContext) *cobra.Command { case "md": err = doc.GenMarkdownTree(rootCmd, docDirectory) case "rest": - err = doc.GenReSTTree(rootCmd, docDirectory) + err = genReSTTreeCustom(rootCmd, docDirectory, "Hasura CLI: ", func(s string) string { return "" }, sphinxLinkHandler) case "yaml": err = doc.GenYamlTree(rootCmd, docDirectory) default: @@ -51,3 +58,210 @@ func NewDocsCmd(ec *cli.ExecutionContext) *cobra.Command { f.StringVar(&docDirectory, "directory", "docs", "directory where docs should be generated") return docsCmd } + +func sphinxLinkHandler(name, ref string) string { + return fmt.Sprintf(":ref:`%s <%s>`", name, ref) +} + +// taken from https://github.com/spf13/cobra/blob/master/doc/rest_docs.go +func printOptionsReST(buf *bytes.Buffer, cmd *cobra.Command, name string) error { + flags := cmd.NonInheritedFlags() + flags.SetOutput(buf) + if flags.HasFlags() { + buf.WriteString("Options\n") + buf.WriteString("~~~~~~~\n\n::\n\n") + flags.PrintDefaults() + buf.WriteString("\n") + } + + parentFlags := cmd.InheritedFlags() + parentFlags.SetOutput(buf) + if parentFlags.HasFlags() { + buf.WriteString("Options inherited from parent commands\n") + buf.WriteString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n::\n\n") + parentFlags.PrintDefaults() + buf.WriteString("\n") + } + return nil +} + +// linkHandler for default ReST hyperlink markup +func defaultLinkHandler(name, ref string) string { + return fmt.Sprintf("`%s <%s.rst>`_", name, ref) +} + +// genReST creates reStructured Text output. +func genReST(cmd *cobra.Command, w io.Writer, titlePrefix string) error { + return genReSTCustom(cmd, w, titlePrefix, defaultLinkHandler) +} + +// genReSTCustom creates custom reStructured Text output. +func genReSTCustom(cmd *cobra.Command, w io.Writer, titlePrefix string, linkHandler func(string, string) string) error { + cmd.InitDefaultHelpCmd() + cmd.InitDefaultHelpFlag() + + buf := new(bytes.Buffer) + name := cmd.CommandPath() + ref := strings.Replace(name, " ", "_", -1) + cliDocPath := "manifests/docs/" + ref + ".rst" + short := cmd.Short + long := cmd.Long + if len(long) == 0 { + long = short + } + fileInfo, er := assets.Asset(cliDocPath) + var info string + if er != nil || string(fileInfo) == "" { + info = short + } else { + info = string(fileInfo) + } + + buf.WriteString(".. _" + ref + ":\n\n") + + buf.WriteString(titlePrefix + name + "\n") + buf.WriteString(strings.Repeat("-", len(titlePrefix+name)) + "\n\n") + buf.WriteString(info + "\n\n") + + buf.WriteString("Synopsis\n") + buf.WriteString("~~~~~~~~\n\n") + buf.WriteString("\n" + long + "\n\n") + + if cmd.Runnable() { + buf.WriteString(fmt.Sprintf("::\n\n %s\n\n", cmd.UseLine())) + } + + if len(cmd.Aliases) > 0 { + buf.WriteString("Alias: " + strings.Join(cmd.Aliases, ", ") + "\n\n") + } + + if len(cmd.Example) > 0 { + buf.WriteString("Examples\n") + buf.WriteString("~~~~~~~~\n\n") + buf.WriteString(fmt.Sprintf("::\n\n%s\n\n", indentString(cmd.Example, " "))) + } + + if err := printOptionsReST(buf, cmd, name); err != nil { + return err + } + if hasSeeAlso(cmd) { + buf.WriteString("SEE ALSO\n") + buf.WriteString("~~~~~~~~\n\n") + if cmd.HasParent() { + parent := cmd.Parent() + pname := parent.CommandPath() + ref = strings.Replace(pname, " ", "_", -1) + buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(pname, ref), parent.Short)) + cmd.VisitParents(func(c *cobra.Command) { + if c.DisableAutoGenTag { + cmd.DisableAutoGenTag = c.DisableAutoGenTag + } + }) + } + + children := cmd.Commands() + sort.Sort(byName(children)) + + for _, child := range children { + if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() { + continue + } + cname := name + " " + child.Name() + ref = strings.Replace(cname, " ", "_", -1) + buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(cname, ref), child.Short)) + } + buf.WriteString("\n") + } + if !cmd.DisableAutoGenTag { + buf.WriteString("*Auto generated by spf13/cobra*\n") + } + _, err := buf.WriteTo(w) + return err +} + +// genReSTTree will generate a ReST page for this command and all +// descendants in the directory given. +// This function may not work correctly if your command names have `-` in them. +// If you have `cmd` with two subcmds, `sub` and `sub-third`, +// and `sub` has a subcommand called `third`, it is undefined which +// help output will be in the file `cmd-sub-third.1`. +func genReSTTree(cmd *cobra.Command, dir, titlePrefix string) error { + emptyStr := func(s string) string { return "" } + return genReSTTreeCustom(cmd, dir, titlePrefix, emptyStr, defaultLinkHandler) +} + +// genReSTTreeCustom is the the same as genReSTTree, but +// with custom filePrepender and linkHandler. +func genReSTTreeCustom(cmd *cobra.Command, dir, titlePrefix string, filePrepender func(string) string, linkHandler func(string, string) string) error { + for _, c := range cmd.Commands() { + if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { + continue + } + if err := genReSTTreeCustom(c, dir, titlePrefix, filePrepender, linkHandler); err != nil { + return err + } + } + + basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".rst" + filename := filepath.Join(dir, basename) + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + if _, err := io.WriteString(f, filePrepender(filename)); err != nil { + return err + } + if err := genReSTCustom(cmd, f, titlePrefix, linkHandler); err != nil { + return err + } + return nil +} + +// adapted from: https://github.com/kr/text/blob/main/indent.go +func indentString(s, p string) string { + var res []byte + b := []byte(s) + prefix := []byte(p) + bol := true + for _, c := range b { + if bol && c != '\n' { + res = append(res, prefix...) + } + res = append(res, c) + bol = c == '\n' + } + return string(res) +} + +// Test to see if we have a reason to print See Also information in docs +// Basically this is a test for a parent commend or a subcommand which is +// both not deprecated and not the autogenerated help command. +func hasSeeAlso(cmd *cobra.Command) bool { + if cmd.HasParent() { + return true + } + for _, c := range cmd.Commands() { + if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { + continue + } + return true + } + return false +} + +// Temporary workaround for yaml lib generating incorrect yaml with long strings +// that do not contain \n. +func forceMultiLine(s string) string { + if len(s) > 60 && !strings.Contains(s, "\n") { + s = s + "\n" + } + return s +} + +type byName []*cobra.Command + +func (s byName) Len() int { return len(s) } +func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() } diff --git a/cli/commands/help.go b/cli/commands/help.go new file mode 100644 index 0000000000000..1bc8ed8ebac5f --- /dev/null +++ b/cli/commands/help.go @@ -0,0 +1,87 @@ +package commands + +import ( + "fmt" + "os" + "text/tabwriter" + + "github.com/hasura/graphql-engine/cli" + "github.com/spf13/cobra" +) + +type commandGroup struct { + Title string + Commands []*cobra.Command +} + +// NewHelpCmd returns the help command +func NewHelpCmd(ec *cli.ExecutionContext) *cobra.Command { + opts := &helpOptions{ + EC: ec, + } + var helpCmd = &cobra.Command{ + Use: "help", + Short: "Help about any command", + Long: "Help provides help for any command in the CLI", + Run: func(cmd *cobra.Command, args []string) { + opts.Cmd = cmd + opts.Args = args + opts.run() + }, + } + return helpCmd +} + +type helpOptions struct { + EC *cli.ExecutionContext + + Cmd *cobra.Command + Args []string +} + +func (o *helpOptions) run() { + topLevelCommands := []commandGroup{ + { + Title: "GraphQL commands", + Commands: []*cobra.Command{ + NewInitCmd(o.EC), + NewMigrateCmd(o.EC), + NewMetadataCmd(o.EC), + NewConsoleCmd(o.EC), + }, + }, + { + Title: "Other commands", + Commands: []*cobra.Command{ + NewCompletionCmd(o.EC), + NewVersionCmd(o.EC), + }, + }, + } + c := o.Cmd + args := o.Args + cmd, _, e := c.Root().Find(args) + if cmd == nil || e != nil { + c.Printf("Unknown help topic %#q\n", args) + c.Root().Usage() + } else { + if cmd.Name() == "hasura" { + // root command + fmt.Println(cmd.Long) + w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) + for _, g := range topLevelCommands { + fmt.Println(g.Title + ":") + for _, gc := range g.Commands { + fmt.Fprintf(w, " %s\t%s\n", gc.Name(), gc.Short) + } + w.Flush() + fmt.Println("") + } + fmt.Println(`Use "hasura [command] --help" for more information about a command.`) + } else { + cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown + cmd.Help() + } + } + +} diff --git a/cli/commands/root.go b/cli/commands/root.go index ac07ae2d846aa..079354620745d 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -9,6 +9,15 @@ import ( "github.com/spf13/cobra" ) +const HasuraASCIIText = ` + __ + / /_ ____ _ _____ __ __ _____ ____ _ + / __ \ / __ ` + "`" + `// ___// / / // ___// __ ` + "`" + `/ + / / / // /_/ /(__ )/ /_/ // / / /_/ / +/_/ /_/ \__,_//____/ \__,_//_/ \__,_/ + +` + // ec is the Execution Context for the current run. var ec *cli.ExecutionContext @@ -16,6 +25,7 @@ var ec *cli.ExecutionContext var rootCmd = &cobra.Command{ Use: "hasura", Short: "Hasura GraphQL Engine command line tool", + Long: HasuraASCIIText, SilenceUsage: true, SilenceErrors: true, PersistentPreRun: func(cmd *cobra.Command, args []string) { @@ -33,6 +43,14 @@ var rootCmd = &cobra.Command{ } } }, + Run: func(cmd *cobra.Command, args []string) { + o := helpOptions{ + EC: ec, + Cmd: cmd, + Args: args, + } + o.run() + }, } func init() { @@ -44,8 +62,10 @@ func init() { NewMigrateCmd(ec), NewVersionCmd(ec), NewDocsCmd(ec), + NewCompletionCmd(ec), NewUpdateCLICmd(ec), ) + rootCmd.SetHelpCommand(NewHelpCmd(ec)) f := rootCmd.PersistentFlags() f.StringVar(&ec.LogLevel, "log-level", "INFO", "log level (DEBUG, INFO, WARN, ERROR, FATAL)") f.StringVar(&ec.ExecutionDirectory, "project", "", "directory where commands are executed. (default: current dir)") diff --git a/cli/get.sh b/cli/get.sh index f80f461bfc9a3..8e6ad90147380 100755 --- a/cli/get.sh +++ b/cli/get.sh @@ -1,116 +1,141 @@ +#!/usr/bin/env bash + +# Some helpful functions +yell() { echo -e "${RED}FAILED> $* ${NC}" >&2; } +die() { yell "$*"; exit 1; } +try() { "$@" || die "failed executing: $*"; } +log() { echo -e "--> $*"; } + +# Colors for colorizing +RED='\033[0;31m' +GREEN='\033[0;32m' +PURPLE='\033[0;35m' +BLUE='\033[0;34m' +YELLOW='\033[0;33m' +NC='\033[0m' + +INSTALL_PATH=${INSTALL_PATH:-"/usr/local/bin"} +NEED_SUDO=0 + +function maybe_sudo() { + if [[ "$NEED_SUDO" == '1' ]]; then + sudo "$@" + else + "$@" + fi +} + +# check for curl +hasCurl=$(which curl) +if [ "$?" = "1" ]; then + die "You need to install curl to use this script." +fi + +log "Getting latest version..." + # adapted from https://github.com/openfaas/faas-cli/blob/master/get.sh version=$(curl -s -H 'Content-Type: text/plain' https://releases.hasura.io/graphql-engine?agent=cli-get.sh) if [ ! $version ]; then - echo "Failed while attempting to install hasura graphql-engine cli. Please manually install:" - echo "" - echo "1. Open your web browser and go to https://github.com/hasura/graphql-engine/releases" - echo "2. Download the cli from latest release for your platform. Call it 'hasura'." - echo "3. chmod +x ./hasura" - echo "4. mv ./hasura /usr/local/bin" - exit 1 + log "${YELLOW}" + log "Failed while attempting to install hasura graphql-engine cli. Please manually install:" + log "" + log "2. Open your web browser and go to https://github.com/hasura/graphql-engine/releases" + log "2. Download the cli from latest release for your platform. Name it 'hasura'." + log "3. chmod +x ./hasura" + log "4. mv ./hasura /usr/local/bin" + log "${NC}" + die "exiting..." fi -hasCli() { - - has=$(which hasura) - - if [ "$?" = "0" ]; then - echo - echo "You already have the hasura cli!" - export n=3 - echo "Overwriting in $n seconds.. Press Control+C to cancel." - echo - sleep $n - fi - - hasCurl=$(which curl) - if [ "$?" = "1" ]; then - echo "You need curl to use this script." - exit 1 - fi -} +log "Latest version is $version" + +# check for existing hasura installation +hasCli=$(which hasura) +if [ "$?" = "0" ]; then + log "" + log "${GREEN}You already have the hasura cli at '${hasCli}'${NC}" + export n=3 + log "${YELLOW}Downloading again in $n seconds... Press Ctrl+C to cancel.${NC}" + log "" + sleep $n +fi +# get platform and arch +platform='unknown' +unamestr=`uname` +if [[ "$unamestr" == 'Linux' ]]; then + platform='linux' +elif [[ "$unamestr" == 'Darwin' ]]; then + platform='darwin' +fi -getPackage() { - uname=$(uname) - userid=$(id -u) - - suffix="" - case $uname in - "Darwin") - suffix="-darwin-amd64" - ;; - "Linux") - arch=$(uname -m) - case $arch in - "amd64" | "x86_64") - suffix="-linux-amd64" - ;; - esac - case $arch in - "aarch64") - suffix="-linux-arm64" - ;; - esac - case $arch in - "armv6l" | "armv7l") - suffix="-linux-armhf" - ;; - esac - ;; - esac - - targetFile="/tmp/cli-hasura$suffix" - - if [ "$userid" != "0" ]; then - targetFile="$(pwd)/cli-hasura$suffix" - fi +if [[ "$platform" == 'unknown' ]]; then + die "Unknown OS platform" +fi - if [ -e $targetFile ]; then - rm $targetFile - fi +arch='unknown' +archstr=`uname -m` +if [[ "$archstr" == 'x86_64' ]]; then + arch='amd64' +else + arch='386' +fi - url=https://github.com/hasura/graphql-engine/releases/download/$version/cli-hasura$suffix - echo "Downloading package $url as $targetFile" +# some variables +suffix="-${platform}-${arch}" +targetFile="/tmp/cli-hasura$suffix" - curl -sSL $url --output $targetFile +if [ -e $targetFile ]; then + rm $targetFile +fi - if [ "$?" = "0" ]; then +log "${PURPLE}Downloading hasura for $platform-$arch to ${targetFile}${NC}" +url=https://github.com/hasura/graphql-engine/releases/download/$version/cli-hasura$suffix - chmod +x $targetFile +try curl -L# -o $targetFile "$url" +try chmod +x $targetFile - echo "Download complete." +log "${GREEN}Download complete!${NC}" - if [ "$userid" != "0" ]; then - - echo - echo "=========================================================" - echo "== As the script was run as a non-root user the ==" - echo "== following command may need to be run manually ==" - echo "=========================================================" - echo - echo " sudo cp cli-hasura$suffix /usr/local/bin/hasura" - echo +# check for sudo +needSudo=$(touch ${INSTALL_PATH}/.hasurainstall &> /dev/null) +if [[ "$?" == "1" ]]; then + NEED_SUDO=1 +fi +rm ${INSTALL_PATH}/.hasurainstall &> /dev/null + +if [[ "$NEED_SUDO" == '1' ]]; then + log + log "${YELLOW}Path '$INSTALL_PATH' requires root access to write." + log "${YELLOW}This script will attempt to execute the move command with sudo.${NC}" + log "${YELLOW}Are you ok with that? (y/N)${NC}" + read a + if [[ $a == "Y" || $a == "y" || $a = "" ]]; then + log + else + log + log " ${BLUE}sudo mv $targetFile ${INSTALL_PATH}/hasura${NC}" + log + die "Please move the binary manually using the command above." + fi +fi - else +log "Moving cli from $targetFile to ${INSTALL_PATH}" - echo - echo "Running as root - Attempting to move hasura cli to /usr/local/bin" +try maybe_sudo mv $targetFile ${INSTALL_PATH}/hasura - mv $targetFile /usr/local/bin/hasura - - if [ "$?" = "0" ]; then - echo "New version of hasura cli installed to /usr/local/bin" - fi +log +log "${GREEN}hasura cli installed to ${INSTALL_PATH}${NC}" +log - if [ -e $targetFile ]; then - rm $targetFile - fi +if [ -e $targetFile ]; then + rm $targetFile +fi - hasura version - fi - fi -} +hasura version -hasCli -getPackage \ No newline at end of file +if ! $(echo "$PATH" | grep -q "$INSTALL_PATH"); then + log + log "${YELLOW}$INSTALL_PATH not found in \$PATH, you might need to add it${NC}" + log +fi \ No newline at end of file diff --git a/docs/graphql/manual/hasura-cli/hasura.rst b/docs/graphql/manual/hasura-cli/hasura.rst index b011ccd266dc7..bf06f9c84db7d 100644 --- a/docs/graphql/manual/hasura-cli/hasura.rst +++ b/docs/graphql/manual/hasura-cli/hasura.rst @@ -3,18 +3,20 @@ Hasura CLI: hasura ------------------ -``hasura`` is the CLI that manages every Hasura project. +Hasura GraphQL Engine command line tool Synopsis ~~~~~~~~ + :: - __ - / /_ ____ _ _____ __ __ _____ ____ _ - / __ \ / __ `// ___// / / // ___// __ `/ - / / / // /_/ /(__ )/ /_/ // / / /_/ / - /_/ /_/ \__,_//____/ \__,_//_/ \__,_/ + __ + / /_ ____ _ _____ __ __ _____ ____ _ + / __ \ / __ `// ___// / / // ___// __ `/ + / / / // /_/ /(__ )/ /_/ // / / /_/ / + /_/ /_/ \__,_//____/ \__,_//_/ \__,_/ + :: @@ -26,19 +28,19 @@ Options :: - -h, --help help for hasura - --project string hasura project directory where the commands should be executed. (default: current directory) + -h, --help help for hasura + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ * :ref:`hasura completion ` - Generate auto completion code * :ref:`hasura console ` - Open console to manage database and try out APIs -* :ref:`hasura example ` - Show some examples for using hasura * :ref:`hasura init ` - Initialize directory for Hasura GraphQL Engine migrations * :ref:`hasura metadata ` - Manage Hasura GraphQL Engine metadata saved in the database * :ref:`hasura migrate ` - Manage migrations on the database -* :ref:`hasura update-cli ` - Update hasura to latest version -* :ref:`hasura version ` - Prints the version of hasura +* :ref:`hasura update-cli ` - Update the CLI to latest version +* :ref:`hasura version ` - Print the CLI version *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_completion.rst b/docs/graphql/manual/hasura-cli/hasura_completion.rst index 52ad2c9bef2cb..3c4e9096981d6 100644 --- a/docs/graphql/manual/hasura-cli/hasura_completion.rst +++ b/docs/graphql/manual/hasura-cli/hasura_completion.rst @@ -20,7 +20,6 @@ Examples :: - # Bash # Linux # Add Bash completion file using: @@ -64,11 +63,12 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_console.rst b/docs/graphql/manual/hasura-cli/hasura_console.rst index 1a27389bc813e..7004a9e58df79 100644 --- a/docs/graphql/manual/hasura-cli/hasura_console.rst +++ b/docs/graphql/manual/hasura-cli/hasura_console.rst @@ -32,7 +32,7 @@ Options :: --access-key string access key for Hasura GraphQL Engine - --address string address to use (default "localhost") + --address string address to serve console and migration API from (default "localhost") --api-port string port for serving migrate api (default "9693") --console-port string port for serving console (default "9695") --endpoint string http(s) endpoint for Hasura GraphQL Engine @@ -45,11 +45,12 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_example.rst b/docs/graphql/manual/hasura-cli/hasura_example.rst deleted file mode 100644 index 45972b6139dbd..0000000000000 --- a/docs/graphql/manual/hasura-cli/hasura_example.rst +++ /dev/null @@ -1,47 +0,0 @@ -.. _hasura_example: - -Hasura CLI: hasura example --------------------------- - -Show some examples for using hasura - -Synopsis -~~~~~~~~ - - -Print examples for using hasura, like quickstarting the project etc. - -:: - - hasura example [flags] - -Alias: examples - -Examples -~~~~~~~~ - -:: - - # Print examples for using hasura - $ hasura examples - -Options -~~~~~~~ - -:: - - -h, --help help for example - -Options inherited from parent commands -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -:: - - --project string hasura project directory where the commands should be executed. (default: current directory) - -SEE ALSO -~~~~~~~~ - -* :ref:`hasura ` - hasura controls the hasura project - -*Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_init.rst b/docs/graphql/manual/hasura-cli/hasura_init.rst index f8dccd6f9abb9..50749d4500406 100644 --- a/docs/graphql/manual/hasura-cli/hasura_init.rst +++ b/docs/graphql/manual/hasura-cli/hasura_init.rst @@ -45,11 +45,12 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_metadata.rst b/docs/graphql/manual/hasura-cli/hasura_metadata.rst index 260da4df7aecb..a7b0b7602bc8f 100644 --- a/docs/graphql/manual/hasura-cli/hasura_metadata.rst +++ b/docs/graphql/manual/hasura-cli/hasura_metadata.rst @@ -23,12 +23,13 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool * :ref:`hasura metadata apply ` - Apply Hasura metadata on a database * :ref:`hasura metadata export ` - Export Hasura GraphQL Engine metadata from the database * :ref:`hasura metadata reload ` - Reload Hasura GraphQL Engine metadata on the database diff --git a/docs/graphql/manual/hasura-cli/hasura_metadata_apply.rst b/docs/graphql/manual/hasura-cli/hasura_metadata_apply.rst index e888d9339fe21..61ca060d592f8 100644 --- a/docs/graphql/manual/hasura-cli/hasura_metadata_apply.rst +++ b/docs/graphql/manual/hasura-cli/hasura_metadata_apply.rst @@ -37,7 +37,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_metadata_export.rst b/docs/graphql/manual/hasura-cli/hasura_metadata_export.rst index 5b5d6e488a6e7..eaab8f055f4bc 100644 --- a/docs/graphql/manual/hasura-cli/hasura_metadata_export.rst +++ b/docs/graphql/manual/hasura-cli/hasura_metadata_export.rst @@ -41,7 +41,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_metadata_reload.rst b/docs/graphql/manual/hasura-cli/hasura_metadata_reload.rst index 0795be364ee92..611b8af03e31a 100644 --- a/docs/graphql/manual/hasura-cli/hasura_metadata_reload.rst +++ b/docs/graphql/manual/hasura-cli/hasura_metadata_reload.rst @@ -37,7 +37,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_metadata_reset.rst b/docs/graphql/manual/hasura-cli/hasura_metadata_reset.rst index 569ebb249aa92..0b8c944acc798 100644 --- a/docs/graphql/manual/hasura-cli/hasura_metadata_reset.rst +++ b/docs/graphql/manual/hasura-cli/hasura_metadata_reset.rst @@ -37,7 +37,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_migrate.rst b/docs/graphql/manual/hasura-cli/hasura_migrate.rst index 70e9a7d5fc102..ff33a83580419 100644 --- a/docs/graphql/manual/hasura-cli/hasura_migrate.rst +++ b/docs/graphql/manual/hasura-cli/hasura_migrate.rst @@ -23,12 +23,13 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool * :ref:`hasura migrate apply ` - Apply migrations on the database * :ref:`hasura migrate create ` - Create files required for a migration * :ref:`hasura migrate status ` - Display current status of migrations on a database diff --git a/docs/graphql/manual/hasura-cli/hasura_migrate_apply.rst b/docs/graphql/manual/hasura-cli/hasura_migrate_apply.rst index b1d51f4ecbb38..0b0b889e29571 100644 --- a/docs/graphql/manual/hasura-cli/hasura_migrate_apply.rst +++ b/docs/graphql/manual/hasura-cli/hasura_migrate_apply.rst @@ -33,7 +33,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_migrate_create.rst b/docs/graphql/manual/hasura-cli/hasura_migrate_create.rst index 21f7129b568e7..562cb50ebb591 100644 --- a/docs/graphql/manual/hasura-cli/hasura_migrate_create.rst +++ b/docs/graphql/manual/hasura-cli/hasura_migrate_create.rst @@ -27,7 +27,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_migrate_status.rst b/docs/graphql/manual/hasura-cli/hasura_migrate_status.rst index cb742e456995a..96429fe83e96e 100644 --- a/docs/graphql/manual/hasura-cli/hasura_migrate_status.rst +++ b/docs/graphql/manual/hasura-cli/hasura_migrate_status.rst @@ -29,7 +29,8 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ diff --git a/docs/graphql/manual/hasura-cli/hasura_update-cli.rst b/docs/graphql/manual/hasura-cli/hasura_update-cli.rst index 078a6d4af562a..26a40723c00f5 100644 --- a/docs/graphql/manual/hasura-cli/hasura_update-cli.rst +++ b/docs/graphql/manual/hasura-cli/hasura_update-cli.rst @@ -3,13 +3,13 @@ Hasura CLI: hasura update-cli ----------------------------- -Update hasura to latest version +Update the CLI to latest version Synopsis ~~~~~~~~ -Automatically download and install the latest version of hasura +Update the CLI to latest version :: @@ -20,11 +20,12 @@ Examples :: - # Update hasura to the latest stable version - $ hasura update-cli + # Update CLI to latest version: + hasura update-cli - # On unix systems, if hasura is installed onto a location that can be accessed only by root, use - $ sudo hasura update-cli + # To disable auto-update check on the CLI, set + # "show_update_notification": false + # in ~/.hasura/config.json Options @@ -39,11 +40,12 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_version.rst b/docs/graphql/manual/hasura-cli/hasura_version.rst index 6852271d4b15d..744012187bad6 100644 --- a/docs/graphql/manual/hasura-cli/hasura_version.rst +++ b/docs/graphql/manual/hasura-cli/hasura_version.rst @@ -3,26 +3,18 @@ Hasura CLI: hasura version -------------------------- -Prints the version of hasura +Print the CLI version Synopsis ~~~~~~~~ -Prints the current installed version of hasura cli +Print the CLI version :: hasura version [flags] -Examples -~~~~~~~~ - -:: - - # To find the current running version of hasura: - $ hasura version - Options ~~~~~~~ @@ -35,11 +27,12 @@ Options inherited from parent commands :: - --project string hasura project directory where the commands should be executed. (default: current directory) + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --project string directory where commands are executed. (default: current dir) SEE ALSO ~~~~~~~~ -* :ref:`hasura ` - hasura controls the hasura project +* :ref:`hasura ` - Hasura GraphQL Engine command line tool *Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/index.rst b/docs/graphql/manual/hasura-cli/index.rst index 0039e756893ff..d376f48b0c94c 100644 --- a/docs/graphql/manual/hasura-cli/index.rst +++ b/docs/graphql/manual/hasura-cli/index.rst @@ -30,11 +30,11 @@ Commands - :doc:`hasura ` - :doc:`hasura completion ` - :doc:`hasura console ` -- :doc:`hasura example ` - :doc:`hasura init ` - :doc:`hasura metadata ` - :doc:`hasura metadata apply ` - :doc:`hasura metadata export ` +- :doc:`hasura metadata reload ` - :doc:`hasura metadata reset ` - :doc:`hasura migrate ` - :doc:`hasura migrate apply ` @@ -57,7 +57,6 @@ Refer to :doc:`uninstall-hasura-cli`. hasura hasura completion hasura console - hasura example hasura init hasura metadata hasura metadata apply diff --git a/docs/graphql/manual/hasura-cli/install-hasura-cli.rst b/docs/graphql/manual/hasura-cli/install-hasura-cli.rst index 09fbfe27281ac..2f05c273ca788 100644 --- a/docs/graphql/manual/hasura-cli/install-hasura-cli.rst +++ b/docs/graphql/manual/hasura-cli/install-hasura-cli.rst @@ -23,40 +23,44 @@ Install .. code-block:: bash - curl -L https://cli.hasura.io/install.sh | bash + curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | bash This will install the Hasura CLI in ``/usr/local/bin``. You might have to provide your ``sudo`` password depending on the permissions of your ``/usr/local/bin`` location. + If you'd prefer to install to a different location other than ``/usr/local/bin``, set the + env var ``INSTALL_PATH``: + + .. code-block:: bash + + curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | INSTALL_PATH=$HOME/bin bash + + + - id: mac content: | In your terminal enter the following command: .. code-block:: bash - curl -L https://cli.hasura.io/install.sh | bash + curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | bash This will install the Hasura CLI in ``/usr/local/bin``. You might have to provide your ``sudo`` password depending on the permissions of your ``/usr/local/bin`` location. - - id: windows - content: | + If you'd prefer to install to a different location other than ``/usr/local/bin``, set the + env var ``INSTALL_PATH``: - .. note:: + .. code-block:: bash - You should have ``git bash`` installed to use Hasura CLI. Download ``git bash`` using this - `link `__. Also, make sure you install it in ``MinTTY`` mode, - instead of Windows' default console. + curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | INSTALL_PATH=$HOME/bin bash - Download the Hasura installer: + - id: windows + content: | - * `hasura (64-bit Windows installer) `__ - * `hasura (32-bit Windows installer) `__ - - **Note:** Please run the installer as ``Administrator`` to avoid PATH update errors. If you're still getting - a "command not found" error after installing Hasura CLI, please restart ``git bash``. + Download the binary ``cli-hasura-windows-amd64.exe`` from GitHub release page: https://github.com/hasura/graphql-engine/releases -Alternatively, you can directly download the appropriate binary from: https://github.com/hasura/graphql-engine/releases + Rename the downloaded file to ``hasura``. (Optional) Add shell completion ------------------------------- diff --git a/docs/graphql/manual/hasura-cli/uninstall-hasura-cli.rst b/docs/graphql/manual/hasura-cli/uninstall-hasura-cli.rst index 55d02efbb542a..e51f504836a03 100644 --- a/docs/graphql/manual/hasura-cli/uninstall-hasura-cli.rst +++ b/docs/graphql/manual/hasura-cli/uninstall-hasura-cli.rst @@ -8,9 +8,11 @@ Uninstalling the Hasura CLI To uninstall the Hasura CLI you just need to delete the binary file from its installation location. -By default, the binary is installed at ``/usr/local/bin/hasura`` - .. code-block:: bash + # By default, the binary is installed at /usr/local/bin/hasura + $ which hasura + /usr/local/bin/hasura + # use sudo if required $ rm /usr/local/bin/hasura