diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..008272a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + commit-message: + prefix: "deps:" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "09:00" + - package-ecosystem: "github-actions" + commit-message: + prefix: "ci:" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "09:00" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7405eb0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: build + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * 0' # run "At 00:00 on Sunday" + +# See https://github.com/cristalhq/.github/.github/workflows +jobs: + build: + uses: cristalhq/.github/.github/workflows/build.yml@v0.8.1 + + vuln: + uses: cristalhq/.github/.github/workflows/vuln.yml@v0.8.1 diff --git a/GUIDE.md b/GUIDE.md new file mode 100644 index 0000000..68fd090 --- /dev/null +++ b/GUIDE.md @@ -0,0 +1 @@ +# Guide for osx diff --git a/README.md b/README.md index 8cf6cf0..aba5448 100644 --- a/README.md +++ b/README.md @@ -1 +1,50 @@ -# osx \ No newline at end of file +# osx + +[![build-img]][build-url] +[![pkg-img]][pkg-url] +[![reportcard-img]][reportcard-url] +[![coverage-img]][coverage-url] +[![version-img]][version-url] + +TODO + +## Features + +* Simple API. + +See [GUIDE.md](https://github.com/cristalhq/osx/blob/main/GUIDE.md) for more details. + +## Install + +Go version 1.18+ + +``` +go get github.com/cristalhq/osx +``` + +## Example + +```go +TODO +``` + +Also see examples: [example_test.go](https://github.com/cristalhq/osx/blob/main/example_test.go). + +## Documentation + +See [these docs][pkg-url]. + +## License + +[MIT License](LICENSE). + +[build-img]: https://github.com/cristalhq/osx/workflows/build/badge.svg +[build-url]: https://github.com/cristalhq/osx/actions +[pkg-img]: https://pkg.go.dev/badge/cristalhq/osx +[pkg-url]: https://pkg.go.dev/github.com/cristalhq/osx +[reportcard-img]: https://goreportcard.com/badge/cristalhq/osx +[reportcard-url]: https://goreportcard.com/report/cristalhq/osx +[coverage-img]: https://codecov.io/gh/cristalhq/osx/branch/main/graph/badge.svg +[coverage-url]: https://codecov.io/gh/cristalhq/osx +[version-img]: https://img.shields.io/github/v/release/cristalhq/osx +[version-url]: https://github.com/cristalhq/osx/releases diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..76265b4 --- /dev/null +++ b/example_test.go @@ -0,0 +1 @@ +package osx_test diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1ce01ae --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/cristalhq/osx + +go 1.18 diff --git a/osx.go b/osx.go new file mode 100644 index 0000000..9c51097 --- /dev/null +++ b/osx.go @@ -0,0 +1,26 @@ +package osx + +import ( + "os" +) + +// IsFile reports wheter file exists. +func IsFile(filename string) bool { + return exists(filename, false) +} + +// IsDir reports wheter directory exists. +func IsDir(dirname string) bool { + return exists(dirname, true) +} + +func exists(name string, dir bool) bool { + switch info, err := os.Stat(name); { + case os.IsNotExist(err): + return false + case dir: + return info.IsDir() + default: + return !info.IsDir() + } +}