{"id":24511354,"url":"https://github.com/hamba/cmd","last_synced_at":"2025-04-14T08:21:48.178Z","repository":{"id":37390579,"uuid":"170509122","full_name":"hamba/cmd","owner":"hamba","description":"Go cmd helper","archived":false,"fork":false,"pushed_at":"2025-04-14T00:37:28.000Z","size":436,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T01:30:01.859Z","etag":null,"topics":["cli","cmd","golang","helper"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hamba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-13T13:04:17.000Z","updated_at":"2025-04-14T00:37:31.000Z","dependencies_parsed_at":"2023-11-20T05:28:26.352Z","dependency_job_id":"bc7eca11-7b96-4f8e-9cf7-1f8a4becad72","html_url":"https://github.com/hamba/cmd","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamba%2Fcmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamba%2Fcmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamba%2Fcmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamba%2Fcmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hamba","download_url":"https://codeload.github.com/hamba/cmd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844038,"owners_count":21170506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cmd","golang","helper"],"created_at":"2025-01-22T00:37:17.754Z","updated_at":"2025-04-14T08:21:48.155Z","avatar_url":"https://github.com/hamba.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](http://svg.wiersma.co.za/hamba/project?title=cmd\u0026tag=Go%20cmd%20helper)\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/hamba/cmd)](https://goreportcard.com/report/github.com/hamba/cmd)\n[![Build Status](https://github.com/hamba/cmd/actions/workflows/test.yml/badge.svg)](https://github.com/hamba/cmd/actions)\n[![Coverage Status](https://coveralls.io/repos/github/hamba/cmd/badge.svg?branch=master)](https://coveralls.io/github/hamba/cmd?branch=master)\n[![Go Reference](https://pkg.go.dev/badge/github.com/hamba/cmd/v2.svg)](https://pkg.go.dev/github.com/hamba/cmd/v2)\n[![GitHub release](https://img.shields.io/github/release/hamba/cmd.svg)](https://github.com/hamba/cmd/releases)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hamba/cmd/master/LICENSE)\n\nGo cmd helper. \n\nThis provides helpers on top of `github.com/urfave/cli`.\n\n## Overview\n\nInstall with:\n\n```shell\ngo get github.com/hamba/cmd/v2\n```\n\n## Example\n\n```go\nfunc yourAction(c *cli.Context) error {\n    log, err := cmd.NewLogger(c)\n\tif err != nil {\n\t\t// Handle error.\n\t}\n\n\tstats, err := cmd.NewStatter(c, log)\n\tif err != nil {\n\t\t// Handle error.\n\t}\n\n    tracer, err := cmd.NewTracer(c, log,\n        semconv.ServiceNameKey.String(\"my-service\"),\n        semconv.ServiceVersionKey.String(\"1.0.0\"),\n    )\n    if err != nil {\n        // Handle error.\n        return\n    }\n    defer tracer.Shutdown(context.Background())\n\n    // Run your application here...\n\t\n\treturn nil\n}\n```\n\n## Flags\n\n### Logger\n\nThe logger flags are used by `cmd.NewLogger` to create a `hamba.Logger`.\n\n#### FlagLogFormat: *--log.format, $LOG_FORMAT*\n\nThis flag sets the log formatter to use. The available options are `logfmt` *(default)*, `json`, `console`.\n\nExample: `--log.format=console`\n\n#### FlagLogLevel: *--log.level, $LOG_LEVEL*\n\nThis flag sets the log level to filer on. The available options are `debug`, `info` (default), `warn`, `error`, `crit`.\n\nExample: `--log.level=error`\n\n#### FlagLogCtx: *--log.ctx, $LOG_CTX*\n\nThis flag sets contextual key value pairs to set on all log messages. This flag can be specified multiple times.\n\nExample: `--log.ctx=\"app=my-app\" --log.ctx=\"zone=eu-west\"`\n\n### Statter\n\nThe statter flags are used by `cmd.NewStatter` to create a new `hamba.Statter.\n\n#### FlagStatsDSN: *--stats.dsn, $STATS_DSN*\n\nThis flag sets the DSN describing the stats reporter to use. The available options are `statsd`, `prometheus`, `l2met`, `victoriametrics`.\n\nThe DSN can in some situations specify the host and configuration values as shown in the below examples:\n\n**Statsd:** \n\n`--stats.dsn=\"statsd://host:port?flushBytes=1432\u0026flushInterval=10s\"`\n\nThe `host` and `port` are required. Optionally `flushBytes` and `flushInterval` can be set, controlling how often the stats will\nbe sent to the Statsd server.\n\n**Prometheus:**\n\n`--stats.dsn=\"prometheus://host:port\"`\n\nor\n\n`--stats.dsn=\"prom://host:port\"`\n\nThe `host` and `port` are optional. If set they will start a prometheus http server on the specified host and port.\n\n**Victoria Metrics:**\n\n`--stats.dsn=\"victoriametrics://host:port\"`\n\nor\n\n`--stats.dsn=\"vm://host:port\"`\n\nThe `host` and `port` are optional. If set they will start a victoria metrics http server on the specified host and port.\n\n**l2met:**\n\n`--stats.dsn=\"l2met://\"`\n\nThis report has no exposed options.\n\n#### FlagStatsInterval: *--stats.interval, $STATS_INTERVAL*\n\nThis flag sets the interval at which the aggregated stats will be reported to the reporter.\n\nExample: `--stats-interval=10s`\n\n#### FlagStatsPrefix: *--stats.prefix, $STATS_PREFIX*\n\nThis flag sets the prefix attached to all stats keys.\n\nExample: `--stats.prefix=my-app.server`\n\n#### FlagStatsTags: *--stats.tags, $STATS_TAGS*\n\nThis flag sets tag key value pairs to set on all stats. This flag can be specified multiple times.\n\nExample: `--stats.tags=\"app=my-app\" --stats.tags=\"zone=eu-west\"`\n\n### Profiler\n\nThe profiler flags are used by `cmd.NewProfiler` to create a Pyroscope `*pyroscope.Profiler`.\n\n#### FlagProfilingDSN: *--profiling.dsn, $PROFILING_DSN*\n\nThis flag configures the URL, authentication and optionally the Tenant ID for Pyroscope.\n\nExample: `--profiling.dsn=https://user:pass@host/path?token=auth-token\u0026tenantid=my-tenant-id`\n\n#### FlagProfileUploadRate: *--profiling.upload-rate, $PROFILING_UPLOAD_RATE*\n\nThis flag configures the rate at which profiles are uploaded.\n\nExample: `--profiling.upload-rate=10s`\n\n#### FlagProfilingTags: *--profiling.tags, $PROFILING_TAGS*\n\nThis configures a list of tags appended to every profile. This flag can be specified multiple times.\n\nExample: `--profiling.tags=\"app=my-app\" --profiling.tags=\"zone=eu-west\"`\n\n#### FlagProfilingTypes: *--profiling.types, $PROFILING_TYPES*\n\nThis configures the profile types that are captured. By default all supported types are captured. This flag can be specified multiple times.\n\nExample: `--profiling.types=cpu --profiling.types=inuse_object`\n\n### Tracer\n\nThe tracing flags are used by `cmd.NewTracer` to create a new open telemetry `trace.TraceProvider`.\n\n#### FlagTracingExporter: *--tracing.exporter, $TRACING_EXPORTER*\n\nThis flag sets the exporter to send spans to. The available options are `zipkin`, `otlphttp` and `otlpgrpc`.\n\nExample: `--tracing.exporter=otlphttp`\n\n#### FlagTracingEndpoint: *--tracing.endpoint, $TRACING_ENDPOINT*\n\nThis flag sets the endpoint the exporter should send traces to.\n\nExample: `--tracing.endpoint=\"agent-host:port\"` or `--tracing.endpoint=\"http://host:port/api/v2\"`\n\n#### FlagTracingEndpointInsecure: *--tracing.endpoint-insecure, $TRACING_ENDPOINT_INSECURE*\n\nThis flag sets the endpoint the exporter should send traces to.\n\nExample: `--tracing.endpoint-insecure`\n\n#### FlagTracingRatio: *--tracing.ratio, $TRACING_RATIO*\n\nThis flag sets the sample ratio of spans that will be reported to the exporter. This should be between 0 and 1.\n\nExample: `--tracing.ratio=0.2`\n\n#### FlagTracingTags: *--tracing.tags, $TRACING_TAGS*\n\nThis flag sets a list of tags appended to every trace. This flag can be specified multiple times.\n\nExample: `--tracing.tags=\"app=my-app\" --tracing.tags=\"zone=eu-west\"`\n\n### Observer\n\nThe observe package exposes an `Observer` type which is essentially a helper that combines a logger, tracer and statter.\nIt is useful if you use all three for your services and want to avoid carrying around many arguments.\n\nHere is an example of how one might use it:\n\n```go\nfunc yourAction(c *cli.Context) error {\n     obsvr, err := observe.NewFromCLI(c, \"my-service\", \u0026observe.Options{\n        LogTimestamps: true,\n        StatsRuntime:  true,\n        TracingAttrs: []attribute.KeyValue{\n            semconv.ServiceVersionKey.String(\"1.0.0\"),\n        },\n    })\n    if err != nil {\n        return err\n    }\n    defer obsvr.Close()\n\n\t// Run your application here...\n\n\treturn nil\n}\n```\n\nIt also exposes `NewFake` which allows you to pass fake loggers, tracers and statters in your tests easily.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamba%2Fcmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamba%2Fcmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamba%2Fcmd/lists"}