1
0

main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "gogs.dmsc.dev/arp/arp_cli/cmd"
  9. "github.com/urfave/cli/v3"
  10. )
  11. func main() {
  12. // Create context with cancellation for graceful shutdown
  13. ctx, cancel := context.WithCancel(context.Background())
  14. defer cancel()
  15. // Handle interrupt signals
  16. sigChan := make(chan os.Signal, 1)
  17. signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
  18. go func() {
  19. <-sigChan
  20. cancel()
  21. }()
  22. // Build and run the CLI
  23. app := &cli.Command{
  24. Name: "arp_cli",
  25. Usage: "Command-line interface for ARP (Agent-native ERP)",
  26. Description: `ARP CLI is a command-line tool for interacting with ARP GraphQL servers.
  27. It provides CRUD operations for Services, Users, Notes, Tasks, Messages,
  28. Roles, and Permissions. Real-time updates are available via WebSocket subscriptions
  29. for Tasks and Messages.
  30. First, login to an ARP server using 'arp_cli login' to store your credentials.
  31. Then use the various commands to manage your ARP data.`,
  32. Version: "1.0.0",
  33. Flags: []cli.Flag{
  34. &cli.StringFlag{
  35. Name: "url",
  36. Aliases: []string{"u"},
  37. Usage: "ARP server URL",
  38. Sources: cli.EnvVars("ARP_URL"),
  39. },
  40. &cli.StringFlag{
  41. Name: "output",
  42. Aliases: []string{"o"},
  43. Usage: "Output format (table, json)",
  44. Value: "table",
  45. },
  46. },
  47. Commands: []*cli.Command{
  48. cmd.RootCommand(),
  49. cmd.LoginCommand(),
  50. cmd.ConfigCommand(),
  51. cmd.ServiceCommand(),
  52. cmd.UserCommand(),
  53. cmd.NoteCommand(),
  54. cmd.TaskCommand(),
  55. cmd.MessageCommand(),
  56. cmd.RoleCommand(),
  57. cmd.PermissionCommand(),
  58. },
  59. Before: func(ctx context.Context, command *cli.Command) (context.Context, error) {
  60. // Store global flags in context for later use
  61. return ctx, nil
  62. },
  63. }
  64. if err := app.Run(ctx, os.Args); err != nil {
  65. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  66. os.Exit(1)
  67. }
  68. }