diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-28 06:16:07 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-28 06:16:07 +0200 |
| commit | 9eacbb42f9a5931bf33d968f775fc806c46b11b0 (patch) | |
| tree | bf9a34182b2db560023ba0deb060146bdbcc0d34 /list.go | |
| parent | 4137fae6df4e77198b8ddd9d9647a1ee0c7c49d3 (diff) | |
| download | colabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.tar.gz colabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.zip | |
Init
Diffstat (limited to 'list.go')
| -rw-r--r-- | list.go | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -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) +} |
