DirectRun direct run plugin from command line. cmd: type is cobra.Command args: command line arguments pluginTask: specific built-in plugin, for example: feishu, jira... options: plugin config
(cmd *cobra.Command, args []string, pluginTask plugin.PluginTask, options map[string]interface{}, timeAfter string)
| 50 | // pluginTask: specific built-in plugin, for example: feishu, jira... |
| 51 | // options: plugin config |
| 52 | func DirectRun(cmd *cobra.Command, args []string, pluginTask plugin.PluginTask, options map[string]interface{}, timeAfter string) { |
| 53 | basicRes := CreateAppBasicRes() |
| 54 | tasks, err := cmd.Flags().GetStringSlice("subtasks") |
| 55 | if err != nil { |
| 56 | panic(err) |
| 57 | } |
| 58 | fullSync, err := cmd.Flags().GetBool("fullsync") |
| 59 | if err != nil { |
| 60 | panic(err) |
| 61 | } |
| 62 | if pluginInit, ok := pluginTask.(plugin.PluginInit); ok { |
| 63 | err = pluginInit.Init(basicRes) |
| 64 | if err != nil { |
| 65 | panic(err) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | err = plugin.RegisterPlugin(cmd.Use, pluginTask.(plugin.PluginMeta)) |
| 70 | if err != nil { |
| 71 | panic(err) |
| 72 | } |
| 73 | |
| 74 | // collect migration and run |
| 75 | migrator, err := InitMigrator(basicRes) |
| 76 | if err != nil { |
| 77 | panic(err) |
| 78 | } |
| 79 | migrator.Register(migrationscripts.All(), "Framework") |
| 80 | if migratable, ok := pluginTask.(plugin.PluginMigration); ok { |
| 81 | migrator.Register(migratable.MigrationScripts(), cmd.Use) |
| 82 | } |
| 83 | err = migrator.Execute() |
| 84 | if err != nil { |
| 85 | panic(err) |
| 86 | } |
| 87 | ctx := createContext() |
| 88 | task := &models.Task{ |
| 89 | Plugin: cmd.Use, |
| 90 | Options: options, |
| 91 | Subtasks: tasks, |
| 92 | } |
| 93 | parsedTimeAfter := time.Time{} |
| 94 | syncPolicy := models.SyncPolicy{} |
| 95 | if timeAfter != "" { |
| 96 | parsedTimeAfter, err = time.Parse(time.RFC3339, timeAfter) |
| 97 | if err != nil { |
| 98 | panic(err) |
| 99 | } |
| 100 | syncPolicy.TimeAfter = &parsedTimeAfter |
| 101 | } |
| 102 | syncPolicy.FullSync = fullSync |
| 103 | |
| 104 | err = RunPluginSubTasks( |
| 105 | ctx, |
| 106 | basicRes, |
| 107 | task, |
| 108 | pluginTask, |
| 109 | nil, |
nothing calls this directly
no test coverage detected