utils

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProgramName = "jotl"
)

Variables

This section is empty.

Functions

func AcquireLock

func AcquireLock() (*flock.Flock, error)

AcquireLock attempts to create and lock a session lock file

func CheckGitConfig

func CheckGitConfig(key string) (bool, error)

func CreateDatabase

func CreateDatabase(currentDir string, dbDriver string) error

CreateDatabase sets up the database for the jotl project based on the specified driver. For SQLite, it creates a database file in the jotl directory. For PostgreSQL, it assumes the database is managed externally and does not create any files (well except for a docker-compose.yaml).

func CreateEnvFile

func CreateEnvFile(currentDir string, cfg *config.JotlConfig) error

CreateEnvFile creates a .env file with the configuration

func DeleteJotlOnFail

func DeleteJotlOnFail(currentDir string) error

DeleteJotlOnFail deletes the Jotl configuration directory if an error occurs.

func EnsureGitignore

func EnsureGitignore(dir string) error

EnsureGitignore checks if a .gitignore file exists in the given directory, creates it if it does not exist, and ensures that the /jotl directory is ignored.

func ExecuteCmd

func ExecuteCmd(name string, args []string, dir string) error

ExecuteCmd provides a shorthand way to run a shell command

func FindAvailablePort

func FindAvailablePort(startPort int) string

func GetDevEnvironment

func GetDevEnvironment() string

GetDevEnvironment scans the project directory to detect the language server

func InitializeJotlDirectory

func InitializeJotlDirectory(currentDir, dbDriver string) error

InitializeJotlDirectory creates the necessary directory structure and files for jotl. It creates the following structure: root directory/

		└── jotl/
    		├── db/
    		│   ├── .env
    		│   └── jotl.db
    		└── jotl.config.yaml

This structure is exclusive of postgres driver

func InstallDatabaseDrivers

func InstallDatabaseDrivers(dbDriver string) error

InstallDatabaseDrivers installs the specified database driver package using the `go get` command. Supported database drivers are "postgres" and "sqlite".

func IsGitDirectory

func IsGitDirectory(dir string) bool

IsGitDirectory checks if the given directory is a Git repository. It returns true if the directory contains a .git directory or a .git file (which can be the case for git submodules or alternative git configurations). It returns false otherwise.

func IsJotlInitialized

func IsJotlInitialized(startDir string) bool

IsJotlInitialized checks whether a jotl project has been initialized already in the directory tree. It returns true if the jotl directory and its necessary files exist.

func NonInteractiveCommand

func NonInteractiveCommand(use string, flagSet *pflag.FlagSet) string

NonInteractiveCommand creates the command string from a flagSet to be used for getting the equivalent non-interactive shell command

func OpenBrowser

func OpenBrowser(url string)

openBrowser attempts to open the default web browser with the given URL.

func ParsePort

func ParsePort(port string) int

parsePort converts a string port to an integer.

func ReleaseLock

func ReleaseLock(fl *flock.Flock) error

ReleaseLock releases and deletes the session lock file

func ServeConfig

func ServeConfig(port string) error

func ValidateModuleName

func ValidateModuleName(moduleName string) bool

ValidateModuleName checks if the provided module name is valid. A valid module name can contain alphanumeric characters, underscores, hyphens, and can be separated by dots or slashes. It returns true if it's a valid module name.

Types

type ConfigPaths

type ConfigPaths struct {
	ConfigDir  string
	ConfigFile string
	DBDir      string
}

func GetConfigPaths

func GetConfigPaths(currentDir string) ConfigPaths

GetConfigPaths returns the necessary paths for configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL