GithubHelp home page GithubHelp logo

Treblle CLI

Integrations   •   Website   •   Docs   •   Blog   •   Twitter   •   Discord


A framework for building CLI applications fluently in Go.

This is currently unreleased, and is a work in progress. Breaking Changes are expected.

Usage

To start you need to create your main.go and create a new application

const (
	AppDir = "/.your-app"
)

func main() {
    app := app.New(
        "CLI Name", // The Name of your CLI Application
        AppDir, // The path within ~/.config to create CLI configuration
        1000, // The number of parallel workers you want to be available for dispatching tasks
    )

    app.Boot() // This will boot the application, setting the storage path for this run.

    // If you need to load your CLI config from a file you can do that using a fluent interface
    app.Config.LoadFromFile(app.Storage.Path + "/config.go")
}

Once you have a basic application set up, you can move onto registering your commands using the fluent builder interface

func main() {
    ... other code goes here

    RegisterCommands(app) // Register all the commands in your application

    app.Console.RootCmd.Execute() // Execute your main command
}

func RegisterCommands(app *app.App) {
    app.Console.Register(
		console.
			Build("test"). // The name of the command
			Description("Test command"). // the description (short) for the command
			Action(func(cmd *cobra.Command, args []string) {
				log.Info("Test Command Called") // what you want this command to do
			}
        ),
	)
}

Using the HTTP Client

func main() {
    ... other code goes here

    request := app.Http.Base("https://api.treblle.com/").WithToken("123123")

	var message Message

	response, err := request.Get("/")
	if err != nil {
		log.Errorf("Request error: %v\n", err)
		os.Exit(1)
	}

	log.Infof("Success: %v", response.JSON(&message))
}

Using the Applications Queue

You can start your applications queue runner, which will listen on a wait group for Jobs to be passed into it

func main() {
    ... other code goes here

    runner := app.Queue

	runner.Run()
}

func SomeOtherMethod() {
    var wg sync.WaitGroup
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			job := &ExampleJob{Message: fmt.Sprintf("Hello, I am job number %d", i)}
			dispatcher.JobQueue <- job
		}(i)
	}
	wg.Wait()
}

Using the Event Dispatcher

func main() {
    ... other code goes here

    // Register listeners
	app.Dispatcher.Event("UserRegistered").
		Listen(func(data event.EventData) {
			userData, _ := data.(map[string]string)
			println("Send welcome email to:", userData["email"])
		}).
		Listen(func(data event.EventData) {
			println("Log user registration to audit trail.")
		})
}

func SomeOtherMethod() {
    // Dispatch event
	app.Dispatcher.Event("UserRegistered").Dispatch(map[string]string{
		"email": "[email protected]",
		"name":  "John Doe",
	})
}

Examples

Community 💙

First and foremost: Star and watch this repository to stay up-to-date.

Also, follow our Blog, and on Twitter.

You can chat with the team and other members on Discord and follow our tutorials and other video material at YouTube.

Treblle Discord

Treblle YouTube

Treblle on Twitter

How to contribute

Here are some ways of contributing to making Treblle better:

  • Try out Treblle, and let us know ways to make Treblle better for you. Let us know here on Discord.
  • Join our Discord and connect with other members to share and learn from.
  • Send a pull request to any of our open source repositories on Github. Check the contribution guide on the repo you want to contribute to for more details about how to contribute. We're looking forward to your contribution!

Contributors

A table of avatars from the project's contributors

treblle's Projects

api-boilerplate-laravel icon api-boilerplate-laravel

Experience the power of Treblle API Boilerplate for Laravel - version 2. Explore our latest enhancements and join a vibrant community of developers committed to optimizing API development.

api-insights-action icon api-insights-action

Use this GitHub Action to run a report on your OpenAPI Specification within your CI Pipeline.

api-responses icon api-responses

Elevate your API response consistency with this specialized package. Designed for intuitive integration within your controllers, it guarantees straightforward and standardized API responses, simplifying the process for you.

awesome-api-tools icon awesome-api-tools

A curated list of awesome tools, bookmarks, tutorials, and other cool resources for the API ecosystem. The list is divided into categories, making it easy to find the resources you need.

community icon community

Treblle community is the meta-repo for our community to hold discussions, and point to areas in the Treblle community for our members

dotnet-api-boilerplate icon dotnet-api-boilerplate

An awesome boilerplate for your next .NET 6.0 based API. Its only goal is to simply kick-start your API development and provide you with some of the best practices when building amazing and scalable REST APIs

error-codes icon error-codes

Treblle Error Codes is a PHP package that makes it easy to provide consistent error codes in your applications. With this package, you can easily determine the appropriate error code for any situation, and then access the associated attributes for that code

funxtion-php icon funxtion-php

The SDK from Treblle Hacktoberfest 2023 for the Funxtion API

hackathon-submission icon hackathon-submission

This repository will serve as a hackathon submission of all the projects created by developers during 3rd March - 27th March 2024

laravel-api-boilerplate icon laravel-api-boilerplate

Experience the power of Treblle API Boilerplate for Laravel. Explore our latest enhancements and join a vibrant community of developers committed to optimizing API development. 🚀

nestjs-api-boilerplate icon nestjs-api-boilerplate

Jumpstart your next Typescript-based API project with this boilerplate. Our aim is to accelerate your API development while imparting essential best practices for crafting exceptional and scalable REST APIs

roadmap.treblle.com icon roadmap.treblle.com

We've made the code that drives our roadmap at Treblle available to the public so that you can use it for your own projects.

security-headers icon security-headers

A collection of HTTP middleware classes to improve the security headers in your Laravel application

springboot-api-boilerplate icon springboot-api-boilerplate

An awesome boilerplate for your next Spring boot based API. Its only goal is to simply kick-start your API development and provide you with some of the best practices when building amazing and scalable REST APIs

swag-store icon swag-store

Discover how to build a headless e-commerce store in Laravel through this repository. Use this repo for educational purposes.

treblle icon treblle

A framework enabling Go developers to easily create CLI applications.

treblle-adonisjs icon treblle-adonisjs

The official Treblle SDK for AdonisJS framework. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.

treblle-adonisjs-demo icon treblle-adonisjs-demo

Explore this demo project that guides you through setting up API Monitoring and Observability in your AdonisJS project using the treblle-adonisjs SDK package. Elevate your project's insights and performance monitoring effortlessly.

treblle-api-tools-laravel icon treblle-api-tools-laravel

Unlock the potential of your Laravel API projects with this comprehensive toolkit. Dive in, explore the features, and join our active community to contribute and make API development even better!

treblle-express icon treblle-express

The official Treblle SDK for Express. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.