back_finder

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 6 Imported by: 1

README

back-finder

Lib to navigate up the folder tree to find a file with a given file name.

Why ?

For scripting purpose mostly. That's a little like git works, actually. It detects that there is a .git folder somewhere in a upper directory and allow you to use git commands. If the folder does not exist, that simply means that you are not inside a git tracked folder, and you won't be able to perform most of git actions.

I often have this use case when I need to find a specific file (or check if it exists) in a upper directory for script purpose. Additionally, I wanted an easy-to-use solution instead of relying on the same bash script block that only make script harder to read and manage.

Originally it was a stand-alone application. But since this is a feature that I need to integrate in other application, it has been extracted into a dedicated lib.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilePresence

type FilePresence struct {
	IsFilePresent   bool
	FilePathIfExist string
}

func FileAbsent

func FileAbsent() FilePresence

func FilePresent

func FilePresent(filePath string) FilePresence

func FindFileBetween

func FindFileBetween(fileName string, fromFolder string, backToFolder string) (FilePresence, error)

FindFileBetween try to find a suitable file that should exist inside the

type Folder

type Folder struct {
	Path string
}

func (*Folder) ContainsFile

func (f *Folder) ContainsFile(fileName string) (bool, error)

ContainsFile return a boolean telling if the given filename exist in the folder or an error if it is impossible to infer if the file exist or not.

func (*Folder) NavigateToParent

func (f *Folder) NavigateToParent() string

NavigateToParent update the current Folder one path above ("..") it then returns the new path of the folder, as a string

Jump to

Keyboard shortcuts

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