github.com/robgonnella/ardi/v2@v2.4.5-0.20230102052001-11a49de978c3/main.go (about)

     1  /*
     2  Ardi is a command-line tool for ardiuno that enables you to properly version and
     3  manage project builds, and provides tools to help facilitate the development
     4  process.
     5  
     6  Things ardi can fo for you:
     7  
     8  • Manage versioned platforms and libraries on a per-project basis
     9  
    10  • Store user defined build config for consistent and repeatable builds.
    11  
    12  • Enable running your builds in a CI pipeline
    13  
    14  • Compile and upload to an auto discovered connected board
    15  
    16  • Watch sketch for changes and auto recompile / reupload
    17  
    18  • Print various info about platforms and boards
    19  
    20  • Search and print available libraries and versions
    21  
    22  Ardi should work for all boards and platforms supported by arduino-cli.
    23  */
    24  package main
    25  
    26  import (
    27  	"context"
    28  
    29  	log "github.com/sirupsen/logrus"
    30  
    31  	"github.com/robgonnella/ardi/v2/cli-wrapper"
    32  	"github.com/robgonnella/ardi/v2/commands"
    33  	"github.com/robgonnella/ardi/v2/core"
    34  	"github.com/robgonnella/ardi/v2/util"
    35  )
    36  
    37  func main() {
    38  	ctx, cancel := context.WithCancel(context.Background())
    39  	defer cancel()
    40  	logger := log.New()
    41  
    42  	ardiConfig, svrSettings := util.GetAllSettings()
    43  	cliSettingsPath := util.GetCliSettingsPath()
    44  
    45  	if util.IsProjectDirectory() {
    46  		if err := util.WriteAllSettings(ardiConfig, svrSettings); err != nil {
    47  			logger.WithError(err).Fatal("Failed to write settings files")
    48  		}
    49  	}
    50  
    51  	coreOpts := core.NewArdiCoreOpts{
    52  		Ctx:                ctx,
    53  		Logger:             logger,
    54  		CliSettingsPath:    cliSettingsPath,
    55  		ArdiConfig:         *ardiConfig,
    56  		ArduinoCliSettings: *svrSettings,
    57  	}
    58  
    59  	arduinoCli := cli.NewArduinoCli()
    60  	withArduinoCli := core.WithArduinoCli(arduinoCli)
    61  	ardiCore := core.NewArdiCore(coreOpts, withArduinoCli)
    62  
    63  	env := &commands.CommandEnv{
    64  		ArdiCore: ardiCore,
    65  		Logger:   logger,
    66  	}
    67  
    68  	rootCmd := commands.GetRootCmd(env)
    69  	if err := rootCmd.ExecuteContext(ctx); err != nil {
    70  		logger.WithError(err).Fatal("Command failed")
    71  	}
    72  }