func (opt *SubOptions) Apply(pgrm *Program, Args *SubCommandArgs) (runtime *SubRuntime, shouldContinue bool, retval int, err string) {
	// generate a new runtime variable
	runtime = &SubRuntime{Args: Args}

	// if we have a 'help' argument, print the usage and then exit
	if utils.SliceContainsAny(Args.args, helpLongForm, helpShortForm, helpLiteralForm) {
		pgrm.Print(opt.Usage(Args.Command))
		return
	}

	// if we do not allow a for argument, then we need to ensure that
	if opt.ForArgument == NoFor {
		retval, err = Args.EnsureNoFor()
		if retval != 0 {
			return
		}
	} else {
		runtime.For = Args.Pattern
	}

	// either read a flag
	if opt.Flag != "" {
		runtime.Flag, retval, err = Args.ParseFlag(opt)
		if retval != 0 {
			return
		}
	}

	// read the arguments
	runtime.Argc, runtime.Argv, retval, err = Args.EnsureArguments(opt.MinArgs, opt.MaxArgs)
	if retval != 0 {
		return
	}

	// read the root folder or panic
	if opt.NeedsRoot {
		var e error
		runtime.Root, e = GetRootOrPanic()
		if e != nil {
			err = constants.StringUnableParseRootDirectory
			retval = constants.ErrorMissingConfig
			return
		}
	}

	// read the canfile or panic
	if opt.NeedsCANFILE {
		var e error
		runtime.Canfile, e = GetCanonOrPanic()
		if e != nil {
			err = constants.StringInvalidCanfile
			retval = constants.ErrorMissingConfig
			return
		}
	}

	// everything is ok, so we should continue
	shouldContinue = true
	return
}
// Apply applies the sub-command options to sub-command arguments and runs them
Apply applies the sub-command options to sub-command arguments and runs them
// Apply applies the sub - command options to sub - command arguments and runs them
func (opt *SubOptions) Apply(pgrm *Program, Args *SubCommandArgs) (runtime *SubRuntime, shouldContinue bool, retval int, err string) {
	runtime = &SubRuntime{Args: Args}
	if utils.SliceContainsAny(Args.args, helpLongForm, helpShortForm, helpLiteralForm) {
		pgrm.Print(opt.Usage(Args.Command))
		return
	}
	if opt.ForArgument == NoFor {
		retval, err = Args.EnsureNoFor()
		if retval != 0 {
			return
		}
	} else {
		runtime.For = Args.Pattern
	}
	if opt.Flag != "" {
		runtime.Flag, retval, err = Args.ParseFlag(opt)
		if retval != 0 {
			return
		}
	}
	runtime.Argc, runtime.Argv, retval, err = Args.EnsureArguments(opt.MinArgs, opt.MaxArgs)
	if retval != 0 {
		return
	}
	if opt.NeedsRoot {
		var e error
		runtime.Root, e = GetRootOrPanic()
		if e != nil {
			err = constants.StringUnableParseRootDirectory
			retval = constants.ErrorMissingConfig
			return
		}
	}
	if opt.NeedsCANFILE {
		var e error
		runtime.Canfile, e = GetCanonOrPanic()
		if e != nil {
			err = constants.StringInvalidCanfile
			retval = constants.ErrorMissingConfig
			return
		}
	}
	shouldContinue = true
	return
}
func ( opt * SubOptions ) Apply ( pgrm * Program , Args * SubCommandArgs ) ( runtime * SubRuntime , shouldContinue bool , retval int , err string ) { runtime = & SubRuntime { Args : Args } if utils . SliceContainsAny ( Args . args , helpLongForm , helpShortForm , helpLiteralForm ) { pgrm . Print ( opt . Usage ( Args . Command ) ) return } if opt . ForArgument == NoFor { retval , err = Args . EnsureNoFor ( ) if retval != 0 { return } } else { runtime . For = Args . Pattern } if opt . Flag != " " { runtime . Flag , retval , err = Args . ParseFlag ( opt ) if retval != 0 { return } } runtime . Argc , runtime . Argv , retval , err = Args . EnsureArguments ( opt . MinArgs , opt . MaxArgs ) if retval != 0 { return } if opt . NeedsRoot { var e error runtime . Root , e = GetRootOrPanic ( ) if e != nil { err = constants . StringUnableParseRootDirectory retval = constants . ErrorMissingConfig return } } if opt . NeedsCANFILE { var e error runtime . Canfile , e = GetCanonOrPanic ( ) if e != nil { err = constants . StringInvalidCanfile retval = constants . ErrorMissingConfig return } } shouldContinue = true return }
Apply applies the sub-command options to sub-command arguments and runs them
Apply applies the sub - command options to sub - command arguments and runs them
// generate a new runtime variable // if we have a 'help' argument, print the usage and then exit // if we do not allow a for argument, then we need to ensure that // either read a flag // read the arguments // read the root folder or panic // read the canfile or panic // everything is ok, so we should continue