From 9eacbb42f9a5931bf33d968f775fc806c46b11b0 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Sun, 28 Jun 2026 06:16:07 +0200 Subject: Init --- list.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 list.go (limited to 'list.go') diff --git a/list.go b/list.go new file mode 100644 index 0000000..904cc29 --- /dev/null +++ b/list.go @@ -0,0 +1,58 @@ +package main + +import ( + "fmt" + "os" + "text/tabwriter" + "time" + + "github.com/spf13/cobra" + + "github.com/tetsuo/colabctl/internal/auth" + "github.com/tetsuo/colabctl/internal/drive" +) + +var listCmd = &cobra.Command{ + Use: "list", + Aliases: []string{"ls"}, + Short: "List Colab notebooks from Google Drive", + RunE: func(cmd *cobra.Command, _ []string) error { + requireCredentials() + + httpClient, err := auth.Client(cmd.Context(), clientID, clientSecret) + if err != nil { + return err + } + + driveClient, err := drive.New(cmd.Context(), httpClient) + if err != nil { + return err + } + + notebooks, err := driveClient.ListNotebooks(cmd.Context()) + if err != nil { + return err + } + + if len(notebooks) == 0 { + fmt.Println("No Colab notebooks found in your Drive.") + return nil + } + + w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) + fmt.Fprintln(w, "ID\tNAME\tMODIFIED") + fmt.Fprintln(w, "--\t----\t--------") + for _, nb := range notebooks { + modified := nb.Modified + if t, err := time.Parse(time.RFC3339, nb.Modified); err == nil { + modified = t.Format("2006-01-02 15:04") + } + fmt.Fprintf(w, "%s\t%s\t%s\n", nb.ID, nb.Name, modified) + } + return w.Flush() + }, +} + +func init() { + rootCmd.AddCommand(listCmd) +} -- cgit v1.3.1