pathname

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: GPL-3.0 Imports: 6 Imported by: 14

README

pathname

Yum

Go Report Card GitHub Workflow Status License

What is this?

A minimal Go port of Ruby's Pathname class. This mostly contains functions I use a lot such as Basename, Dirname, and ExpandPath. Ruby's Exist? method has been renamed DoesExist to be more Go-like.

How to install

Open a terminal and run the following:

$ go get --ldflags "-s -w" --trimpath -u github.com/mjwhitta/pathname

How to use

Below is a sample usage to expand file paths accounting for ~ use:

package main

import (
    "fmt"

    "github.com/mjwhitta/pathname"
)

func main() {
    if ok, e := pathname.DoesExist("~/bin"); e != nil {
        panic(e)
    } else if ok {
        fmt.Println(pathname.ExpandPath("~/bin"))
    }

    if ok, e := pathname.DoesExist("~user/bin"); e != nil {
        panic(e)
    } else if ok {
        fmt.Println(pathname.Dirname("~user/bin"))
        fmt.Println(pathname.Basename("~user/bin"))
    }
}

Documentation

Index

Constants

View Source
const Version string = "1.2.6"

Version is the package version.

Variables

This section is empty.

Functions

func Basename

func Basename(path string) string

Basename wraps filepath.Base(path str).

func Dirname

func Dirname(path string) string

Dirname wraps filepath.Dir(path str).

func DoesExist

func DoesExist(path string) (bool, error)

DoesExist returns whether or not the file exists on disk. An error is returned, if the path is not accessible.

func ExpandPath

func ExpandPath(path string) string

ExpandPath will expand the specified path accounting for ~ or ~user shortcuts as well as ENV vars.

Types

This section is empty.

Jump to

Keyboard shortcuts

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