aboutsummaryrefslogtreecommitdiff
path: root/list.go
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-28 06:16:07 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-28 06:16:07 +0200
commit9eacbb42f9a5931bf33d968f775fc806c46b11b0 (patch)
treebf9a34182b2db560023ba0deb060146bdbcc0d34 /list.go
parent4137fae6df4e77198b8ddd9d9647a1ee0c7c49d3 (diff)
downloadcolabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.tar.gz
colabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.zip
Init
Diffstat (limited to 'list.go')
-rw-r--r--list.go58
1 files changed, 58 insertions, 0 deletions
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)
+}