cliutils

module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT

README

CLIUtils

A set of cli command for bopher crypto, maintenance, database migration and storage packages.

Note: All cli commands need a resolver function. Resolver functions return dependency by name (Crypto driver, Cache driver, etc.).

Crypto

HashCommand

Hash string using registered cryptography driver.

Driver flag is optional and default driver used if this flag not passed. When using multiple crypto driver, this flag used by resolver function to get crypto driver by name.

Valid hash algorithms is: MD4, MD5, SHA1, SHA256, SHA256224, SHA384, SHA512, SHA512224, SHA512256, SHA3224, SHA3256, SHA3384, SHA3512, KECCAK256 and KECCAK512.

myApp hash [String to hash] [Algorithm] --driver
// Signature:
HashCommand(resolver func(driver string) crypto.Crypto, defDriver string) *cobra.Command

// Example
import "github.com/bopher/cliutils/crypto"
rootCmd.AddCommand(crypto.HashCommand(myResolver, "--APP-CRYPTO"))

Maintenance

Set application maintenance mode on or off. this commands use cache maintenance key for setting this mode on or off.

Note: Default "github.com/bopher/http" maintenance middleware use this cache key for setting maintenance mode on or off.

Down

Turn maintenance mode on.

Driver flag is optional and default driver used if this flag not passed. When using multiple cache driver, this flag used by resolver function to get cache driver by name.

myApp down --driver
// Signature:
DownCommand(resolver func(driver string) cache.Cache, defDriver string) *cobra.Command

// Example
import "github.com/bopher/cliutils/maintenance"
rootCmd.AddCommand(maintenance.DownCommand(myResolver, "--APP-CACHE"))
Up

Turn maintenance mode off.

Driver flag is optional and default driver used if this flag not passed. When using multiple cache driver, this flag used by resolver function to get cache driver by name.

myApp up --driver
// Signature:
UpCommand(resolver func(driver string) cache.Cache, defDriver string) *cobra.Command

// Example
import "github.com/bopher/cliutils/maintenance"
rootCmd.AddCommand(maintenance.UpCommand(myResolver, "--APP-CACHE"))

Migration

A set of command for migrating and seeding SQL database. This package use pure SQL file for migrating.

Driver flag is optional and default driver used if this flag not passed. When using multiple database driver, this flag used by resolver function to get database driver by name.

Migration and seed files directory will get at register time and also can set by flags.

Note: This package use "github.com/jmoiron/sqlx" as database driver.

Note: All sub commands automatically registered when main migration command registered.

myApp migration [command] --driver --migration_dir --seed_dir
# or simply
myApp migration [command] -d -m -s
// Signature:
MigrationCommand(resolver func(driver string) *sqlx.DB, defDriver string, migDir string, seedDir string) *cobra.Command

// Example
import "github.com/bopher/cliutils/migration"
rootCmd.AddCommand(migration.MigrationCommand(myResolver, "--APP-DB", "./database/migrations", "./database/seeds"))
Clear

Delete all database table.

myApp migration clear --driver
Migrate

Migrate database.

myApp migration migrate --driver --migration_dir
Migrated

Show migrated files list.

myApp migration migrated --driver
Seed

Seed database.

myApp migration seed --driver --seed_dir
Seeded

Show seeded files list.

myApp migration seeded --driver

Storage

Clear

Clear storage directory.

Note: For cleaning all directory in storage path, you can pass all instead of directory name.

myApp clear [Directory name or all for clear anything]
// Signature:
ClearCommand(storagePath string) *cobra.Command

// Example
import "github.com/bopher/cliutils/storage"
rootCmd.AddCommand(storage.ClearCommand("./storage"))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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