Documentation
¶
Overview ¶
Package cli implements all canvas-cli commands using cobra.
Index ¶
- Variables
- func CheckAndPreview(cfg *config.ResolvedConfig, w io.Writer, spec *MutationSpec) (bool, error)
- func Execute(version string) int
- func GetConfig(ctx context.Context) *config.ResolvedConfig
- func NewAnnouncementsCmd() *cobra.Command
- func NewApiCmd() *cobra.Command
- func NewAssignmentsCmd() *cobra.Command
- func NewAuthCmd() *cobra.Command
- func NewCoursesCmd() *cobra.Command
- func NewDiscussionsCmd() *cobra.Command
- func NewDoctorCmd() *cobra.Command
- func NewEnrollmentsCmd() *cobra.Command
- func NewFilesCmd() *cobra.Command
- func NewGradingCmd() *cobra.Command
- func NewInboxCmd() *cobra.Command
- func NewMeCmd() *cobra.Command
- func NewModulesCmd() *cobra.Command
- func NewPagesCmd() *cobra.Command
- func NewRootCmd(version string) *cobra.Command
- func NewRubricsCmd() *cobra.Command
- func NewSectionsCmd() *cobra.Command
- func NewSubmissionsCmd() *cobra.Command
- func NewUsersCmd() *cobra.Command
- func RecordAudit(cfg *config.ResolvedConfig, spec *MutationSpec, responseStatus int, ...)
- func Run(ctx context.Context, cfg *config.ResolvedConfig, w io.Writer, jsonMode bool, ...) error
- func WithConfig(ctx context.Context, cfg *config.ResolvedConfig) context.Context
- type DoctorCheck
- type Doer
- type DownloadOptions
- type DownloadResult
- type ExportContextOpts
- type ExportMeta
- type ExportResult
- type GradeImportResult
- type ManifestEntry
- type MutationSpec
- type PartialFailureError
Constants ¶
This section is empty.
Variables ¶
var ( Version = "dev" Commit = "unknown" Date = "unknown" )
Version information injected at build time via ldflags.
Functions ¶
func CheckAndPreview ¶ added in v0.4.0
func CheckAndPreview(cfg *config.ResolvedConfig, w io.Writer, spec *MutationSpec) (bool, error)
CheckAndPreview evaluates the safety policy and, on dry-run, prints the preview to w and returns true so the handler short-circuits. Returns an *exitError when the safety policy blocks the operation.
func Execute ¶
Execute is the top-level entry point used by main.go. It runs the root command and maps any error to a process exit code per docs/json-contract.md.
func GetConfig ¶
func GetConfig(ctx context.Context) *config.ResolvedConfig
GetConfig retrieves the ResolvedConfig from the context, or nil if absent.
func NewAnnouncementsCmd ¶
NewAnnouncementsCmd returns the `announcements` parent command.
func NewAssignmentsCmd ¶
NewAssignmentsCmd returns the `assignments` parent command with all subcommands.
func NewAuthCmd ¶
NewAuthCmd returns the `auth` parent command with all subcommands.
func NewCoursesCmd ¶
NewCoursesCmd returns the `courses` parent command with all subcommands.
func NewDiscussionsCmd ¶
NewDiscussionsCmd returns the `discussions` parent command.
func NewEnrollmentsCmd ¶
NewEnrollmentsCmd returns the `enrollments` parent command.
func NewFilesCmd ¶
NewFilesCmd returns the `files` parent command.
func NewGradingCmd ¶
NewGradingCmd returns the `grade` parent command.
func NewInboxCmd ¶
NewInboxCmd returns the `inbox` parent command.
func NewModulesCmd ¶
NewModulesCmd returns the `modules` parent command with all subcommands.
func NewPagesCmd ¶
NewPagesCmd returns the `pages` parent command.
func NewRootCmd ¶
func NewRubricsCmd ¶
NewRubricsCmd returns the `rubrics` parent command.
func NewSectionsCmd ¶
NewSectionsCmd returns the `sections` parent command.
func NewSubmissionsCmd ¶
NewSubmissionsCmd returns the `submissions` parent command.
func NewUsersCmd ¶
NewUsersCmd returns the `users` parent command.
func RecordAudit ¶ added in v0.4.0
func RecordAudit(cfg *config.ResolvedConfig, spec *MutationSpec, responseStatus int, success bool)
RecordAudit writes an audit event for a mutation outcome.
func Run ¶ added in v0.4.0
func Run(ctx context.Context, cfg *config.ResolvedConfig, w io.Writer, jsonMode bool, spec *MutationSpec, do Doer, humanFn func(w io.Writer, data any) error) error
Run executes a mutation through the full pipeline: safety check, dry-run preview, canvas call, audit logging, and output. In JSON mode it writes the success/error envelope; otherwise humanFn (if non-nil) renders the result.
func WithConfig ¶
WithConfig returns a new context with the given ResolvedConfig attached.
Types ¶
type DoctorCheck ¶
type DoctorCheck struct {
Check string `json:"check"`
Status string `json:"status"` // "pass", "fail", "warn"
Message string `json:"message"`
}
DoctorCheck represents a single diagnostic check result.
type Doer ¶ added in v0.4.0
type Doer func(ctx context.Context, client *canvas.Client) (data any, responseStatus int, err error)
Doer performs the Canvas API call inside Run, returning the result data (for JSON output), the HTTP response status (for audit), and any error.
type DownloadOptions ¶
type DownloadOptions struct {
NoOverwrite bool
}
DownloadOptions controls submission download behavior.
type DownloadResult ¶
type DownloadResult struct {
Total int `json:"total"`
Downloaded int `json:"downloaded"`
Failed int `json:"failed"`
ManifestPath string `json:"manifest_path"`
}
DownloadResult holds the outcome of a submissions download operation.
func DownloadSubmissions ¶
func DownloadSubmissions(ctx context.Context, client *canvas.Client, courseID, assignmentID, outDir string, opts DownloadOptions) (*DownloadResult, error)
DownloadSubmissions downloads all submission attachments for an assignment. It lists submissions, downloads each attachment into a deterministic directory structure, and writes manifest.json and manifest.ndjson.
type ExportContextOpts ¶
ExportContextOpts controls which sections to fetch and filtering behavior.
type ExportMeta ¶
type ExportMeta struct {
GeneratedAt string `json:"generated_at"`
CourseID string `json:"course_id"`
SectionsRequested []string `json:"sections_requested"`
SectionsSucceeded []string `json:"sections_succeeded"`
SectionsFailed []string `json:"sections_failed,omitempty"`
Warnings []string `json:"warnings,omitempty"`
RequestCount int `json:"request_count"`
DurationMS int64 `json:"duration_ms"`
}
ExportMeta holds metadata about the export run.
type ExportResult ¶
type ExportResult struct {
Course any `json:"course,omitempty"`
Tabs []any `json:"tabs,omitempty"`
Modules []any `json:"modules,omitempty"`
Assignments []any `json:"assignments,omitempty"`
AssignmentGroups []any `json:"assignment_groups,omitempty"`
Files []any `json:"files,omitempty"`
Folders []any `json:"folders,omitempty"`
Pages []any `json:"pages,omitempty"`
Announcements []any `json:"announcements,omitempty"`
Discussions []any `json:"discussions,omitempty"`
Quizzes []any `json:"quizzes,omitempty"`
Rubrics []any `json:"rubrics,omitempty"`
Enrollments []any `json:"enrollments,omitempty"`
Sections []any `json:"sections,omitempty"`
CalendarEvents []any `json:"calendar_events,omitempty"`
Submissions []any `json:"submissions,omitempty"`
Grades []any `json:"grades,omitempty"`
ExportMeta ExportMeta `json:"_export_meta"`
}
ExportResult is the top-level JSON shape for the export.
func ExportContext ¶
func ExportContext(ctx context.Context, client *canvas.Client, courseID string, opts ExportContextOpts) (*ExportResult, error)
ExportContext fetches multiple Canvas API endpoints and returns an aggregated result.
type GradeImportResult ¶
type GradeImportResult struct {
Total int `json:"total"`
Imported int `json:"imported"`
Failed int `json:"failed"`
Warnings []string `json:"warnings,omitempty"`
}
GradeImportResult holds the result of a CLI grade import operation.
type ManifestEntry ¶
type ManifestEntry struct {
SubmissionID string `json:"submission_id"`
UserID string `json:"user_id"`
UserName string `json:"user_name"`
SortableName string `json:"sortable_name"`
AttachmentID string `json:"attachment_id"`
Filename string `json:"filename"`
OriginalURL string `json:"original_url"`
LocalPath string `json:"local_path"`
Size int64 `json:"size"`
DownloadStatus string `json:"download_status"`
Error string `json:"error,omitempty"`
}
ManifestEntry represents a single file entry in the download manifest.
type MutationSpec ¶ added in v0.4.0
type MutationSpec struct {
Command string
Level safety.SafetyLevel
Method string
Path string
DryRun bool
Confirm bool
ResourceIDs []string
PayloadSummary string
AuditBody string
Resource map[string]string
}
MutationSpec describes a write operation for the centralized safety, dry-run, audit, and error-normalization pipeline.
type PartialFailureError ¶
type PartialFailureError struct {
Result *DownloadResult
Errors []error
}
PartialFailureError is returned when some file downloads fail but others succeed.
func (*PartialFailureError) Error ¶
func (e *PartialFailureError) Error() string
func (*PartialFailureError) ExitCode ¶
func (e *PartialFailureError) ExitCode() int
ExitCode returns 8, matching the partial-failure exit code contract.