Browse Source

cmd: tighten up env var usage sections (#2962)

Also, document OLLAMA_HOST client semantics per command that honors it.
This looks nicer than having a general puprose environment variable
section in the root usage which was showing up after the "addition help
topics" section outputed by Cobra's default template.

It was decided this was easier to work with than using a custom template
for Cobra right now.
Blake Mizerany 1 year ago
parent
commit
2ada81e068
1 changed files with 24 additions and 15 deletions
  1. 24 15
      cmd/cmd.go

+ 24 - 15
cmd/cmd.go

@@ -887,6 +887,14 @@ func versionHandler(cmd *cobra.Command, _ []string) {
 	}
 	}
 }
 }
 
 
+func appendHostEnvDocs(cmd *cobra.Command) {
+	const hostEnvDocs = `
+Environment Variables:
+      OLLAMA_HOST        The host:port or base URL of the Ollama server (e.g. http://localhost:11434)
+`
+	cmd.SetUsageTemplate(cmd.UsageTemplate() + hostEnvDocs)
+}
+
 func NewCLI() *cobra.Command {
 func NewCLI() *cobra.Command {
 	log.SetFlags(log.LstdFlags | log.Lshortfile)
 	log.SetFlags(log.LstdFlags | log.Lshortfile)
 	cobra.EnableCommandSorting = false
 	cobra.EnableCommandSorting = false
@@ -952,7 +960,6 @@ func NewCLI() *cobra.Command {
 	runCmd.Flags().Bool("insecure", false, "Use an insecure registry")
 	runCmd.Flags().Bool("insecure", false, "Use an insecure registry")
 	runCmd.Flags().Bool("nowordwrap", false, "Don't wrap words to the next line automatically")
 	runCmd.Flags().Bool("nowordwrap", false, "Don't wrap words to the next line automatically")
 	runCmd.Flags().String("format", "", "Response format (e.g. json)")
 	runCmd.Flags().String("format", "", "Response format (e.g. json)")
-
 	serveCmd := &cobra.Command{
 	serveCmd := &cobra.Command{
 		Use:     "serve",
 		Use:     "serve",
 		Aliases: []string{"start"},
 		Aliases: []string{"start"},
@@ -963,20 +970,9 @@ func NewCLI() *cobra.Command {
 	serveCmd.SetUsageTemplate(serveCmd.UsageTemplate() + `
 	serveCmd.SetUsageTemplate(serveCmd.UsageTemplate() + `
 Environment Variables:
 Environment Variables:
 
 
-	OLLAMA_HOST
-		The host:port to bind to (default "127.0.0.1:11434")
-
-		Examples:
-			"127.0.0.1:11434"
-	OLLAMA_ORIGINS
-		A comma separated list of allowed origins. If unset, the
-		default behavior is to allow same origin requests, only.
-
-		Examples:
-			"localhost:11434"
-			"example.com,api.example.com"
-	OLLAMA_MODELS
-		The path to the models directory (default is "~/.ollama/models")
+    OLLAMA_HOST       The host:port to bind to (default "127.0.0.1:11434")
+    OLLAMA_ORIGINS    A comma separated list of allowed origins.
+    OLLAMA_MODELS     The path to the models directory (default is "~/.ollama/models")
 `)
 `)
 
 
 	pullCmd := &cobra.Command{
 	pullCmd := &cobra.Command{
@@ -1022,6 +1018,19 @@ Environment Variables:
 		RunE:    DeleteHandler,
 		RunE:    DeleteHandler,
 	}
 	}
 
 
+	for _, cmd := range []*cobra.Command{
+		createCmd,
+		showCmd,
+		runCmd,
+		pullCmd,
+		pushCmd,
+		listCmd,
+		copyCmd,
+		deleteCmd,
+	} {
+		appendHostEnvDocs(cmd)
+	}
+
 	rootCmd.AddCommand(
 	rootCmd.AddCommand(
 		serveCmd,
 		serveCmd,
 		createCmd,
 		createCmd,