loadOwnerArg parses a single owner-slug argument, opens the DB, and loads the owner. On any error it reports to stderr, closes the DB, and returns a non-zero rc with a nil owner/db. On success the caller owns the returned *sql.DB and must Close it.
(args []string, name string)
| 59 | // and returns a non-zero rc with a nil owner/db. On success the caller |
| 60 | // owns the returned *sql.DB and must Close it. |
| 61 | func loadOwnerArg(args []string, name string) (*flowdb.Owner, *sql.DB, int) { |
| 62 | fs := flagSet(name) |
| 63 | if err := fs.Parse(args); err != nil { |
| 64 | return nil, nil, 2 |
| 65 | } |
| 66 | if fs.NArg() < 1 { |
| 67 | fmt.Fprintf(os.Stderr, "error: %s requires an owner slug\n", name) |
| 68 | return nil, nil, 2 |
| 69 | } |
| 70 | slug := fs.Arg(0) |
| 71 | |
| 72 | dbPath, err := flowDBPath() |
| 73 | if err != nil { |
| 74 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 75 | return nil, nil, 1 |
| 76 | } |
| 77 | db, err := flowdb.OpenDB(dbPath) |
| 78 | if err != nil { |
| 79 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 80 | return nil, nil, 1 |
| 81 | } |
| 82 | o, err := flowdb.GetOwner(db, slug) |
| 83 | if err != nil { |
| 84 | db.Close() |
| 85 | if errors.Is(err, sql.ErrNoRows) { |
| 86 | fmt.Fprintf(os.Stderr, "error: no owner %q\n", slug) |
| 87 | return nil, nil, 1 |
| 88 | } |
| 89 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 90 | return nil, nil, 1 |
| 91 | } |
| 92 | return o, db, 0 |
| 93 | } |
| 94 | |
| 95 | // ownerShow renders the owner's accountability surface: metadata, next |
| 96 | // tick, and a live list of what it owns (tasks tagged owner:<slug>), |
no test coverage detected