mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
Failures of tea's own API requests now name what was missing or refused instead of "resource or API endpoint unavailable": issue #999 not found in alice/project repository alice/nope not found on http://localhost:3001 (or you don't have access) issues are disabled for bob/project #1 in alice/project is an issue, not a pull request; view it with: tea issue view 1 alice/old-stuff is archived (read-only); unarchive it with: tea repo edit ... A 404 on a repository endpoint looks the repository up once to tell a missing or hidden repository from a disabled feature, an empty repository or an issue number given to a pull request command. Refusals get their next step, a rejected GITEA_TOKEN and unreachable servers are named, and timeoutError words an expired --timeout. Errors a command already wrapped with its own context, and raw tea api responses, keep their wording. Ctrl-C and SIGTERM exit with 130 without printing an error, and a declined confirmation prints "Canceled." with exit code 3. Signed-off-by: bircni <bircni@icloud.com>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Tea is a scriptable command line tool for Gitea.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"gitea.dev/tea/internal/app"
|
|
"gitea.dev/tea/internal/clierr"
|
|
)
|
|
|
|
func main() {
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
code := run(ctx, app.System(), os.Args[1:])
|
|
stop()
|
|
os.Exit(code)
|
|
}
|
|
|
|
// run executes tea, reports a failure on stderr and returns the exit code. An interrupt exits
|
|
// silently, and a declined confirmation prints only "Canceled.".
|
|
func run(ctx context.Context, deps app.Dependencies, args []string) int {
|
|
err := app.Execute(ctx, deps, args)
|
|
if err != nil && ctx.Err() != nil {
|
|
// Whatever failed after Ctrl-C or SIGTERM failed because of it; the user knows why.
|
|
err = clierr.Wrap(clierr.Interrupted, err)
|
|
}
|
|
code := clierr.ExitCode(err)
|
|
switch {
|
|
case err == nil, code == clierr.Interrupted:
|
|
case code == clierr.Canceled && !errors.Is(err, context.DeadlineExceeded):
|
|
fmt.Fprintln(deps.Streams.ErrOut, "Canceled.")
|
|
default:
|
|
fmt.Fprintf(deps.Streams.ErrOut, "Error: %v\n", app.Explain(ctx, deps, err))
|
|
}
|
|
return code
|
|
}
|