MCPcopy
hub / github.com/larksuite/cli / runShortcut

Function runShortcut

shortcuts/common/runner.go:904–978  ·  view source on GitHub ↗

runShortcut is the execution pipeline for a declarative shortcut. Each step is a clear phase: identity → config → scopes → context → validate → execute.

(cmd *cobra.Command, f *cmdutil.Factory, s *Shortcut, botOnly bool)

Source from the content-addressed store, hash-verified

902// runShortcut is the execution pipeline for a declarative shortcut.
903// Each step is a clear phase: identity → config → scopes → context → validate → execute.
904func runShortcut(cmd *cobra.Command, f *cmdutil.Factory, s *Shortcut, botOnly bool) error {
905 // --print-schema short-circuits everything below: it's pure local
906 // introspection, no identity / scope / network needed. The flag is
907 // only registered when the shortcut opts in via PrintFlagSchema.
908 if s.PrintFlagSchema != nil {
909 if want, _ := cmd.Flags().GetBool("print-schema"); want {
910 flagName, _ := cmd.Flags().GetString("flag-name")
911 out, err := s.PrintFlagSchema(strings.TrimSpace(flagName))
912 if err != nil {
913 // PrintFlagSchema implementations return bare errors; wrap as a
914 // typed validation error so --print-schema (an agent-facing
915 // introspection path) yields a parseable envelope, not a plain
916 // string.
917 if !errs.IsTyped(err) {
918 err = errs.NewValidationError(errs.SubtypeInvalidArgument, "%s", err.Error()).WithCause(err)
919 }
920 return err
921 }
922 if len(out) == 0 {
923 return nil
924 }
925 fmt.Fprintln(f.IOStreams.Out, string(out))
926 return nil
927 }
928 }
929
930 as, err := resolveShortcutIdentity(cmd, f, s)
931 if err != nil {
932 return err
933 }
934
935 config, err := f.Config()
936 if err != nil {
937 return err
938 }
939 // Identity info is now included in the JSON envelope; skip stderr printing.
940 // cmdutil.PrintIdentity(f.IOStreams.ErrOut, as, config, false)
941
942 if err := checkShortcutScopes(f, cmd.Context(), as, config, s.ScopesForIdentity(string(as))); err != nil {
943 return err
944 }
945
946 rctx, err := newRuntimeContext(cmd, f, s, config, as, botOnly)
947 if err != nil {
948 return err
949 }
950
951 if err := validateEnumFlags(rctx, s.Flags); err != nil {
952 return err
953 }
954 if err := resolveInputFlags(rctx, s.Flags); err != nil {
955 return err
956 }
957 if err := output.ValidateJqFlags(rctx.JqExpr, "", rctx.Format); err != nil {
958 return err
959 }
960 if s.Validate != nil {
961 if err := s.Validate(rctx.ctx, rctx); err != nil {

Calls 15

IsTypedFunction · 0.92
NewValidationErrorFunction · 0.92
ValidateJqFlagsFunction · 0.92
RequireConfirmationFunction · 0.92
resolveShortcutIdentityFunction · 0.85
checkShortcutScopesFunction · 0.85
newRuntimeContextFunction · 0.85
validateEnumFlagsFunction · 0.85
resolveInputFlagsFunction · 0.85
handleShortcutDryRunFunction · 0.85
ScopesForIdentityMethod · 0.80
BoolMethod · 0.65