cli

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package cli implements all canvas-cli commands using cobra.

Index

Constants

This section is empty.

Variables

View Source
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

func Execute(version string) int

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

func NewAnnouncementsCmd() *cobra.Command

NewAnnouncementsCmd returns the `announcements` parent command.

func NewApiCmd

func NewApiCmd() *cobra.Command

NewApiCmd returns the `api` parent command with all subcommands.

func NewAssignmentsCmd

func NewAssignmentsCmd() *cobra.Command

NewAssignmentsCmd returns the `assignments` parent command with all subcommands.

func NewAuthCmd

func NewAuthCmd() *cobra.Command

NewAuthCmd returns the `auth` parent command with all subcommands.

func NewCoursesCmd

func NewCoursesCmd() *cobra.Command

NewCoursesCmd returns the `courses` parent command with all subcommands.

func NewDiscussionsCmd

func NewDiscussionsCmd() *cobra.Command

NewDiscussionsCmd returns the `discussions` parent command.

func NewDoctorCmd

func NewDoctorCmd() *cobra.Command

NewDoctorCmd returns the `doctor` command.

func NewEnrollmentsCmd

func NewEnrollmentsCmd() *cobra.Command

NewEnrollmentsCmd returns the `enrollments` parent command.

func NewFilesCmd

func NewFilesCmd() *cobra.Command

NewFilesCmd returns the `files` parent command.

func NewGradingCmd

func NewGradingCmd() *cobra.Command

NewGradingCmd returns the `grade` parent command.

func NewInboxCmd

func NewInboxCmd() *cobra.Command

NewInboxCmd returns the `inbox` parent command.

func NewMeCmd

func NewMeCmd() *cobra.Command

NewMeCmd returns the `me` parent command with all subcommands.

func NewModulesCmd

func NewModulesCmd() *cobra.Command

NewModulesCmd returns the `modules` parent command with all subcommands.

func NewPagesCmd

func NewPagesCmd() *cobra.Command

NewPagesCmd returns the `pages` parent command.

func NewRootCmd

func NewRootCmd(version string) *cobra.Command

func NewRubricsCmd

func NewRubricsCmd() *cobra.Command

NewRubricsCmd returns the `rubrics` parent command.

func NewSectionsCmd

func NewSectionsCmd() *cobra.Command

NewSectionsCmd returns the `sections` parent command.

func NewSubmissionsCmd

func NewSubmissionsCmd() *cobra.Command

NewSubmissionsCmd returns the `submissions` parent command.

func NewUsersCmd

func NewUsersCmd() *cobra.Command

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

func WithConfig(ctx context.Context, cfg *config.ResolvedConfig) context.Context

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

type ExportContextOpts struct {
	Include []string
	Since   string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL