Skip to content

Commit

Permalink
Added version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asasine committed Feb 17, 2024
0 parents commit cf32690
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release-plz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release-plz

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- main
workflow_dispatch:

jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "systemd-directories"
version = "0.1.0"
authors = ["Adam Sasine <adam.sasine@gmail.com>"]
edition = "2021"
description = "A tiny library to retrieve systemd directories following systemd.exec(5)"
homepage = "https://github.com/asasine/systemd-directories"
repository = "https://github.com/asasine/systemd-directories"
license = "MIT"
keywords = ["systemd", "directories"]
categories = ["filesystem", "config"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Adam Sasine

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.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# systemd-directories
A tiny library to retrieve systemd directories following [systemd.exec(5)](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#RuntimeDirectory=).

This library targets Linux when systemd is used as the execution environment.

[![Crates.io Version](https://img.shields.io/crates/v/systemd-directories?logo=rust)](https://crates.io/crates/systemd-directories)
[![Crates.io Documentation](https://docs.rs/systemd-directories/badge.svg)](https://docs.rs/systemd-directories)
[![CI](https://img.shields.io/github/actions/workflow/status/asasine/systemd-directories/rust.yaml?branch=main&logo=github&label=CI)](https://github.com/asasine/systemd-directories/actions/workflows/rust.yaml?query=branch%3Amain)
[![Crates.io Downloads](https://img.shields.io/crates/d/systemd-directories)](https://crates.io/crates/systemd-directories)


# Examples
## Standalone functions
```rust
use systemd_directories;
use std::env;
use std::path::PathBuf;
env::set_var("RUNTIME_DIRECTORY", "/run/foo");
let runtime_dir = systemd_directories::runtime_dir();
assert_eq!(runtime_dir, Some(PathBuf::from("/run/foo")));
```

## `SystemdDirs` Struct
```rust
use systemd_directories::SystemdDirs;
use std::env;
use std::path::Path;
env::set_var("RUNTIME_DIRECTORY", "/run/foo");
let dirs = SystemdDirs::new();
assert_eq!(dirs.runtime_dir(), Some(Path::new("/run/foo")));
```
9 changes: 9 additions & 0 deletions examples/standalone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use systemd_directories;

fn main() {
println!("runtime dir: {:?}", systemd_directories::runtime_dir());
println!("state dir: {:?}", systemd_directories::state_dir());
println!("cache dir: {:?}", systemd_directories::cache_dir());
println!("log dir: {:?}", systemd_directories::logs_dir());
println!("config dir: {:?}", systemd_directories::config_dir());
}
9 changes: 9 additions & 0 deletions examples/standalone_multiple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use systemd_directories;

fn main() {
println!("runtime dir: {:?}", systemd_directories::runtime_dirs());
println!("state dir: {:?}", systemd_directories::state_dirs());
println!("cache dir: {:?}", systemd_directories::cache_dirs());
println!("log dir: {:?}", systemd_directories::logs_dirs());
println!("config dir: {:?}", systemd_directories::config_dirs());
}
11 changes: 11 additions & 0 deletions examples/struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use systemd_directories::SystemdDirs;

fn main() {
// NOTE: These will possibly be empty if not running under systemd
let dirs = SystemdDirs::new();
println!("runtime dir: {:?}", dirs.runtime_dir());
println!("state dir: {:?}", dirs.state_dir());
println!("cache dir: {:?}", dirs.cache_dir());
println!("log dir: {:?}", dirs.logs_dir());
println!("config dir: {:?}", dirs.config_dir());
}
11 changes: 11 additions & 0 deletions examples/struct_multiple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use systemd_directories::SystemdDirs;

fn main() {
// NOTE: These will possibly be empty if not running under systemd
let dirs = SystemdDirs::new();
println!("runtime dir: {:?}", dirs.runtime_dirs());
println!("state dir: {:?}", dirs.state_dirs());
println!("cache dir: {:?}", dirs.cache_dirs());
println!("log dir: {:?}", dirs.logs_dirs());
println!("config dir: {:?}", dirs.config_dirs());
}

0 comments on commit cf32690

Please sign in to comment.