本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/command_factory.NewFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFactory函数的具体用法?Golang NewFactory怎么用?Golang NewFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFactory函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findCommand
func findCommand(cmdName string) (cmd cli.Command) {
fakeUI := &testterm.FakeUI{}
configRepo := testconfig.NewRepository()
pluginConfig := &testPluginConfig.FakePluginConfiguration{}
manifestRepo := manifest.NewManifestDiskRepository()
apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
"auth": net.NewUAAGateway(configRepo, fakeUI),
"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
"uaa": net.NewUAAGateway(configRepo, fakeUI),
})
rpcService, _ := rpc.NewRpcService(nil, nil, nil, nil, api.RepositoryLocator{}, nil)
cmdFactory := command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig, rpcService)
requirementsFactory := &testreq.FakeReqFactory{}
cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, fakeUI)
myApp := app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
for _, cmd := range myApp.Commands {
if cmd.Name == cmdName {
return cmd
}
}
panic(fmt.Sprintf("command %s does not exist", cmdName))
return
}
示例2: createCommandFactory
func createCommandFactory() command_factory.Factory {
fakeUI := &testterm.FakeUI{}
configRepo := testconfig.NewRepository()
manifestRepo := manifest.NewManifestDiskRepository()
apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
"auth": net.NewUAAGateway(configRepo),
"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now),
"uaa": net.NewUAAGateway(configRepo),
})
return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator)
}
示例3: main
func main() {
defer handlePanics(deps.teePrinter)
defer deps.configRepo.Close()
rpcService := newCliRpcServer(deps.teePrinter, deps.teePrinter)
cmdFactory := command_factory.NewFactory(deps.termUI, deps.configRepo, deps.manifestRepo, deps.apiRepoLocator, deps.pluginConfig, rpcService)
requirementsFactory := requirements.NewFactory(deps.termUI, deps.configRepo, deps.apiRepoLocator)
cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, deps.termUI)
pluginsConfig := plugin_config.NewPluginConfig(func(err error) { panic(err) })
pluginList := pluginsConfig.Plugins()
var badFlags string
metaDatas := cmdFactory.CommandMetadatas()
//return only metadata for current command
metaDatas = mergePluginMetaData(metaDatas, pluginList)
if len(os.Args) > 1 {
flags := cmdFactory.GetCommandFlags(os.Args[1])
totalArgs, _ := cmdFactory.GetCommandTotalArgs(os.Args[1])
if args2skip := totalArgs + 2; len(os.Args) >= args2skip {
badFlags = matchArgAndFlags(flags, os.Args[args2skip:])
}
if badFlags != "" {
badFlags = badFlags + "\n\n"
}
}
injectHelpTemplate(badFlags)
theApp := app.NewApp(cmdRunner, metaDatas...)
rpcService.SetTheApp(theApp)
//command `cf` without argument
if len(os.Args) == 1 || os.Args[1] == "help" || requestHelp(os.Args[2:]) {
theApp.Run(os.Args)
} else if cmdFactory.CheckIfCoreCmdExists(os.Args[1]) {
callCoreCommand(os.Args[0:], theApp)
} else {
// run each plugin and find the method/
// run method if exist
ran := rpc.RunMethodIfExists(rpcService, os.Args[1:], pluginList)
if !ran {
theApp.Run(os.Args)
}
}
}
示例4: createCommandFactory
func createCommandFactory() command_factory.Factory {
fakeUI := &testterm.FakeUI{}
configRepo := testconfig.NewRepository()
pluginConfig := &testPluginConfig.FakePluginConfiguration{}
manifestRepo := manifest.NewManifestDiskRepository()
apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
"auth": net.NewUAAGateway(configRepo, fakeUI),
"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
"uaa": net.NewUAAGateway(configRepo, fakeUI),
})
rpcService, _ := rpc.NewRpcService(nil, nil, nil, nil)
return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig, rpcService)
}
示例5: main
func main() {
defer handlePanics()
deps := setupDependencies()
defer deps.configRepo.Close()
cmdFactory := command_factory.NewFactory(deps.termUI, deps.configRepo, deps.manifestRepo, deps.apiRepoLocator)
requirementsFactory := requirements.NewFactory(deps.termUI, deps.configRepo, deps.apiRepoLocator)
cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory)
app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...).Run(os.Args)
gateways := gatewaySliceFromMap(deps.gateways)
net.NewWarningsCollector(deps.termUI, gateways...).PrintWarnings()
}
示例6:
)
JustBeforeEach(func() {
ui := &testterm.FakeUI{}
config := testconfig.NewRepository()
pluginConfig := &testPluginConfig.FakePluginConfiguration{}
manifestRepo := &testmanifest.FakeManifestRepository{}
repoLocator := api.NewRepositoryLocator(config, map[string]net.Gateway{
"auth": net.NewUAAGateway(config, ui),
"cloud-controller": net.NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{}),
"uaa": net.NewUAAGateway(config, ui),
})
rpcService, _ := rpc.NewRpcService(nil, nil, nil, nil, api.RepositoryLocator{}, nil)
cmdFactory := command_factory.NewFactory(ui, config, manifestRepo, repoLocator, pluginConfig, rpcService)
cmdRunner = &FakeRunner{cmdFactory: cmdFactory}
app = NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
})
Describe("trace file integration", func() {
var (
output *bytes.Buffer
)
BeforeEach(func() {
output = bytes.NewBuffer(make([]byte, 1024))
trace.SetStdout(output)
trace.EnableTrace()
})
示例7:
app *cli.App
cmdRunner *FakeRunner
)
JustBeforeEach(func() {
ui := &testterm.FakeUI{}
config := testconfig.NewRepository()
manifestRepo := &testmanifest.FakeManifestRepository{}
repoLocator := api.NewRepositoryLocator(config, map[string]net.Gateway{
"auth": net.NewUAAGateway(config),
"cloud-controller": net.NewCloudControllerGateway(config, time.Now),
"uaa": net.NewUAAGateway(config),
})
cmdFactory := command_factory.NewFactory(ui, config, manifestRepo, repoLocator)
cmdRunner = &FakeRunner{cmdFactory: cmdFactory}
app = NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
})
Describe("trace file integration", func() {
var (
output *bytes.Buffer
)
BeforeEach(func() {
output = bytes.NewBuffer(make([]byte, 1024))
trace.SetStdout(output)
trace.EnableTrace()
})
示例8: main
func main() {
commands_loader.Load()
defer handlePanics(deps.TeePrinter)
defer deps.Config.Close()
//////////////// non-codegangsta path ///////////////////////
//handles `cf` | `cf -h` || `cf -help`
if len(os.Args) == 1 || os.Args[1] == "--help" || os.Args[1] == "-help" ||
os.Args[1] == "--h" || os.Args[1] == "-h" {
help.ShowHelp(help.GetHelpTemplate())
os.Exit(0)
}
//handle `cf -v` for cf version
if len(os.Args) == 2 && os.Args[1] == "-v" {
deps.Ui.Say(os.Args[0] + " version " + cf.Version + "-" + cf.BuiltOnDate)
os.Exit(0)
}
//handles `cf [COMMAND] -h ...`
//rearrage args to `cf help COMMAND` and let `command help` to print out usage
if requestHelp(os.Args[2:]) {
os.Args[2] = os.Args[1]
os.Args[1] = "help"
}
if len(os.Args) > 1 {
cmd := os.Args[1]
if cmdRegistry.CommandExists(cmd) {
meta := cmdRegistry.FindCommand(os.Args[1]).MetaData()
fc := flags.NewFlagContext(meta.Flags)
fc.SkipFlagParsing(meta.SkipFlagParsing)
if requestHelp(os.Args[2:]) {
deps.Ui.Say(cmdRegistry.CommandUsage(cmd))
os.Exit(0)
} else {
err := fc.Parse(os.Args[2:]...)
if err != nil {
deps.Ui.Failed("Incorrect Usage\n\n" + err.Error() + "\n\n" + cmdRegistry.CommandUsage(cmd))
}
}
cmdRegistry.SetCommand(cmdRegistry.FindCommand(cmd).SetDependency(deps, false))
cfCmd := cmdRegistry.FindCommand(cmd)
reqs, err := cfCmd.Requirements(requirements.NewFactory(deps.Ui, deps.Config, deps.RepoLocator), fc)
if err != nil {
deps.Ui.Failed(err.Error())
}
for _, r := range reqs {
if !r.Execute() {
os.Exit(1)
}
}
cfCmd.Execute(fc)
os.Exit(0)
}
}
//////////////////////////////////////////
rpcService := newCliRpcServer(deps.TeePrinter, deps.TeePrinter)
cmdFactory := command_factory.NewFactory(deps.Ui, deps.Config, deps.ManifestRepo, deps.RepoLocator, deps.PluginConfig, rpcService)
requirementsFactory := requirements.NewFactory(deps.Ui, deps.Config, deps.RepoLocator)
cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, deps.Ui)
pluginsConfig := plugin_config.NewPluginConfig(func(err error) { deps.Ui.Failed(fmt.Sprintf("Error read/writing plugin config: %s, ", err.Error())) })
pluginList := pluginsConfig.Plugins()
var badFlags string
metaDatas := cmdFactory.CommandMetadatas()
//return only metadata for current command
metaDatas = mergePluginMetaData(metaDatas, pluginList)
if len(os.Args) > 1 {
flags := cmdFactory.GetCommandFlags(os.Args[1])
totalArgs, _ := cmdFactory.GetCommandTotalArgs(os.Args[1])
if args2skip := totalArgs + 2; len(os.Args) >= args2skip {
badFlags = matchArgAndFlags(flags, os.Args[args2skip:])
}
if badFlags != "" {
badFlags = badFlags + "\n\n"
}
}
injectHelpTemplate(badFlags)
theApp := app.NewApp(cmdRunner, metaDatas...)
rpcService.SetTheApp(theApp)
if cmdFactory.CheckIfCoreCmdExists(os.Args[1]) {
callCoreCommand(os.Args[0:], theApp)
} else {
// run each plugin and find the method/
// run method if exist
//.........这里部分代码省略.........
示例9: main
func main() {
//make a reference to something in cf/commands/domain, so all init() in the directory will run
_ = domain.CreateDomain{}
defer handlePanics(deps.TeePrinter)
defer deps.Config.Close()
//////////////// non-codegangsta path ///////////////////////
if len(os.Args) > 1 {
cmd := os.Args[1]
if cmdRegistry.CommandExists(cmd) {
meta := cmdRegistry.FindCommand(os.Args[1]).MetaData()
fc := flags.NewFlagContext(meta.Flags)
fc.SkipFlagParsing(meta.SkipFlagParsing)
if requestHelp(os.Args[2:]) {
deps.Ui.Say(cmdRegistry.CommandUsage(cmd))
os.Exit(0)
} else {
err := fc.Parse(os.Args[2:]...)
if err != nil {
deps.Ui.Failed("Incorrect Usage\n\n" + err.Error() + "\n\n" + cmdRegistry.CommandUsage(cmd))
}
}
cmdRegistry.SetCommand(cmdRegistry.FindCommand(cmd).SetDependency(deps, false))
cfCmd := cmdRegistry.FindCommand(cmd)
reqs, err := cfCmd.Requirements(requirements.NewFactory(deps.Ui, deps.Config, deps.RepoLocator), fc)
if err != nil {
deps.Ui.Failed(err.Error())
}
for _, r := range reqs {
if !r.Execute() {
os.Exit(1)
}
}
cfCmd.Execute(fc)
os.Exit(0)
}
}
//////////////////////////////////////////
rpcService := newCliRpcServer(deps.TeePrinter, deps.TeePrinter)
cmdFactory := command_factory.NewFactory(deps.Ui, deps.Config, deps.ManifestRepo, deps.RepoLocator, deps.PluginConfig, rpcService)
requirementsFactory := requirements.NewFactory(deps.Ui, deps.Config, deps.RepoLocator)
cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, deps.Ui)
pluginsConfig := plugin_config.NewPluginConfig(func(err error) { deps.Ui.Failed(fmt.Sprintf("Error read/writing plugin config: %s, ", err.Error())) })
pluginList := pluginsConfig.Plugins()
var badFlags string
metaDatas := cmdFactory.CommandMetadatas()
//return only metadata for current command
metaDatas = mergePluginMetaData(metaDatas, pluginList)
if len(os.Args) > 1 {
flags := cmdFactory.GetCommandFlags(os.Args[1])
totalArgs, _ := cmdFactory.GetCommandTotalArgs(os.Args[1])
if args2skip := totalArgs + 2; len(os.Args) >= args2skip {
badFlags = matchArgAndFlags(flags, os.Args[args2skip:])
}
if badFlags != "" {
badFlags = badFlags + "\n\n"
}
}
injectHelpTemplate(badFlags)
theApp := app.NewApp(cmdRunner, metaDatas...)
rpcService.SetTheApp(theApp)
//command `cf` without argument
if len(os.Args) == 1 || os.Args[1] == "help" || requestHelp(os.Args[2:]) {
theApp.Run(os.Args)
} else if cmdFactory.CheckIfCoreCmdExists(os.Args[1]) {
callCoreCommand(os.Args[0:], theApp)
} else {
// run each plugin and find the method/
// run method if exist
ran := rpc.RunMethodIfExists(rpcService, os.Args[1:], pluginList)
if !ran {
theApp.Run(os.Args)
}
}
}