cmd

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: MIT Imports: 21 Imported by: 1

Documentation

Overview

Package cmd contains all the commands for TEMPest.

Copyright © 2018 Sebastien Bastide Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var CurrTime = time.Now().String()

CurrTime is the current time

View Source
var FooterLog = "=================================================================================================================="

FooterLog is the footer for logs

View Source
var HeaderLog = "=========================  - [" + CurrTime + "] -  ========================="

HeaderLog is the header for logs

View Source
var LinuxAutoStartP string

LinuxAutoStartP is the path to $HOME/.config/autostart/tempest.desktop which is initialized in init()

View Source
var LogShutup string

LogShutup is the path to the log of the 'shutup mode'

View Source
var RootCmd = &cobra.Command{
	Use:   "tempest",
	Short: "TEMPest is a simple CLI to manage temporary directories.",
	Long: `TEMPest is a simple CLI to manage temporary directories.
It is still under development, so it's normal if it's not perfect .. YET!
You can start by checking if the config file exists at:
	~/.tempest/.tempest.yaml
	It contains the files' contraint of age (duration in days).
	It also contains the mode (auto or manual) in which TEMPest runs.
		/!\ note that Windows hasn't been fully tested.

Then you can initialize the list of directories handled by TEMPest. For example:
	tempest init
Then change directory (cd) to a directory you desire to add, and run:
	tempest add
Or just specify the path to the directory (you can add multiple). For example:
	tempest add /tmp/temp.est /temp/test.est

# Note that, by convention, the tempory directories will be called 'temp.est'

To start cleaning targets directories just run:
	tempest start
Or if you want to see what files/folders would get deleted:
	tempest start -t
`,

	Run: func(cmd *cobra.Command, args []string) {

		switch {
		case isVersion:

			if version, errVersion := getVersion(); errVersion != nil {
				color.Red(errVersion.Error())
			} else {
				fmt.Println(color.HiYellowString(version))
			}
		default:

			if errHelp := cmd.Help(); errHelp != nil {
				color.Red(errHelp.Error())
			}
		}
	},
}

RootCmd represents the base command when called without any subcommands TODO Make full description with full help on how to use the CLI

Slash is shorthand for the path separator

View Source
var TempestConfigDir string

TempestConfigDir points to the config directory of TEMPest it holds pretty much all configuration for TEMPest

View Source
var Tempestcf string

Tempestcf is the path to the .tempestcf file this file holds all the paths (targets) of TEMPest

View Source
var Tempestyml string

Tempestyml is the path to the .tempest.yaml file which olds all the the config for the TEMPest tool

View Source
var TempestymlDef string

TempestymlDef is the default path to the .tempest.yaml file use it wisely.

View Source
var WindowsAutoStartSL string

WindowsAutoStartSL is the path to "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\tempest". which is a Symlink to the scripts/startup.bat file, initialized in init()

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FormatSize

func FormatSize(incomingSize float64) (size float64, unit string)

FormatSize takes the size in Bytes and return the new size converted in KByte, MBytes, GBytes when it needs to, plus the unit.

func IsDirectory

func IsDirectory(path string) (bool, error)

IsDirectory returns true if this path points to a directory If there is an error, the func will return it

func IsIntInSlice

func IsIntInSlice(index int, sl []int) bool

IsIntInSlice returns true if the int is in the slice

func IsStringInSlice

func IsStringInSlice(str string, sl []string) bool

IsStringInSlice returns true if the string is in the slice. This one is more simple and faster than checkRedondance(slice, sliceArgs[]string) bool

func Round

func Round(val float64, roundOn float64, places int) (newVal float64)

Round just does what it says it does

func SameSliceValuesStr

func SameSliceValuesStr(a, b []string) bool

SameSliceValuesStr returns “true“ if the two slices fo “string“ have the same values, order doesn't matter

func SameSlices

func SameSlices(a, b []string) bool

SameSlices checks equality between two slices of string returns true if they are identiques

func SameSlicesInt

func SameSlicesInt(a, b []int) bool

SameSlicesInt checks equality between two slices of int returns true if they are identiques

func TreatLastChar

func TreatLastChar(str string) string

TreatLastChar takes a string as parameter. It analyzes the last character of this string, if it is a path separator character, it gets removed. Returns the new path, wether there was change or not.

func WriteLog

func WriteLog(pathLog string, strs ...string)

WriteLog write the strings passed in param into the log file pointed

Types

type Target

type Target struct {
	Index int
	Path  string
}

Target is represented by an index and a path Later this will hold the type(directory or file)

func PathsToTargets

func PathsToTargets(paths []string) []Target

PathsToTargets is a converter, takes paths (strings) and convert them into targets (Target)

Jump to

Keyboard shortcuts

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