// Vim is a sidecar that effectively drives Vim via a simple JSON-based
// API
Vim is a sidecar that effectively drives Vim via a simple JSON-based
API
// Vim is a sidecar that effectively drives Vim via a simple JSON - based // API
func Vim() (exitCode int) {
	defer cleanUp(&exitCode)
	fs := flag.NewFlagSet("vim", flag.PanicOnError)
	bang := fs.Bool("bang", false, "expect command to fail")
	indent := fs.Bool("indent", false, "pretty indent resulting JSON")
	stringout := fs.Bool("stringout", false, "print resulting string rather than JSON encoded version of string")
	fs.Parse(os.Args[1:])
	resp, err := vim(fs.Args())
	if err != nil {
		ef("%v", err)
	}
	if resp.error != nil {
		if !*bang {
			ef("unexpected command error: %v", resp.error)
		}
		fmt.Fprintln(os.Stderr, resp.error)
	}
	if resp.value != nil {
		v := *resp.value
		if *bang {
			ef("unexpected command success")
		}
		if *stringout {
			switch v := v.(type) {
			case string:
				fmt.Print(v)
			default:
				ef("response type is %T, not string", v)
			}
		} else {
			enc := json.NewEncoder(os.Stdout)
			if *indent {
				enc.SetIndent("", "  ")
			}
			if err := enc.Encode(v); err != nil {
				ef("failed to format output of JSON: %v", err)
			}
		}
	}
	return 0
}
func Vim ( ) ( exitCode int ) { defer cleanUp ( & exitCode ) fs := flag . NewFlagSet ( " " , flag . PanicOnError ) bang := fs . Bool ( " " , false , " " ) indent := fs . Bool ( " " , false , " " ) stringout := fs . Bool ( " " , false , " " ) fs . Parse ( os . Args [ 1 : ] ) resp , err := vim ( fs . Args ( ) ) if err != nil { ef ( " " , err ) } if resp . error != nil { if ! * bang { ef ( " " , resp . error ) } fmt . Fprintln ( os . Stderr , resp . error ) } if resp . value != nil { v := * resp . value if * bang { ef ( " " ) } if * stringout { switch v := v . ( type ) { case string : fmt . Print ( v ) default : ef ( " " , v ) } } else { enc := json . NewEncoder ( os . Stdout ) if * indent { enc . SetIndent ( " " , " " ) } if err := enc . Encode ( v ) ; err != nil { ef ( " " , err ) } } } return 0 }
Vim is a sidecar that effectively drives Vim via a simple JSON-based
API
Vim is a sidecar that effectively drives Vim via a simple JSON - based API