Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmmjackson committed Aug 28, 2023
1 parent 651b2ff commit fe52683
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 27 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "upnotify"
description = "A tool that prints to stdout when the status of a URL changes."
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.11.20", features = ["blocking"] }
clap = "4.4.0"
reqwest = { version = "0.11.20", features = ["blocking", "native-tls-vendored"] }
clap = { version = "4.4.0", features = ["cargo"] }

[[bin]]
name = "upnotify"
6 changes: 3 additions & 3 deletions build/aarch64-apple-darwin.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ARCH=arm64
PLATFORM=darwin
UPNOTIFY_BINARY=target/aarch64-apple-darwin/release/upnotify
export ARCH=arm64
export PLATFORM=darwin
export UPNOTIFY_BINARY=target/aarch64-apple-darwin/release/upnotify
3 changes: 3 additions & 0 deletions build/aarch64-unknown-linux-gnu.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export ARCH=arm64
export PLATFORM=linux
export UPNOTIFY_BINARY=target/aarch64-unknown-linux-gnu/release/upnotify
3 changes: 0 additions & 3 deletions build/version.sh

This file was deleted.

3 changes: 3 additions & 0 deletions build/x86_64-apple-darwin.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export ARCH=amd64
export PLATFORM=darwin
export UPNOTIFY_BINARY=target/x86_64-apple-darwin/release/upnotify
3 changes: 3 additions & 0 deletions build/x86_64-unknown-linux-gnu.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export ARCH=amd64
export PLATFORM=linux
export UPNOTIFY_BINARY=target/x86_64-unknown-linux-gnu/release/upnotify
60 changes: 50 additions & 10 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
target:=`rustc -vV | sed -n 's|host: ||p'`
os_family:=os_family()
archive_type:=if os_family == "windows" { "zip" } else { "tarball" }
package_type:="none"
os:=os()
arch:=arch()
version:=`git tag`
version:=`toml get Cargo.toml package.version --raw`
archive_name:="upnotify-{{version}}-{{target}}"
msg:="Unknown error"

default: build

sys-info:
@echo "os_family {{os_family()}}"
@echo "os {{os()}}"
@echo "arch: {{arch()}}"
die:
@echo "Error: {{msg}}"

assert-darwin-host:
@{{ if os == "macos" { "true" } else { "just msg=\"Not a darwin host\" die" } }}

clean:
rm -rf target
rm -rf target dist

build:
cargo build --release --target {{target}}

build-mac-m1:
just target=aarch64-apple-darwin archive
just target=aarch64-apple-darwin assert-darwin-host archive

build-linux-amd64:
docker run --rm --platform linux/amd64 --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp \
rust:1.70.0 sh -c "cargo install just toml-cli && just archive"

build-linux-arm64:
docker run --rm --platform linux/arm64 --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp \
rust:1.70.0 sh -c "cargo install just toml-cli && just archive"

archive-tarball:
tar czf target/{{target}}/release/upnotify-{{version}}-{{target}}.tar.gz target/{{target}}/release/upnotify
tar czf dist/{{target}}/{{archive_name}}.tar.gz target/{{target}}/release/upnotify

archive-zip:
zip target/{{target}}/release/upnotify-{{version}}-{{target}}.zip target/{{target}}/release/upnotify
zip dist/{{target}}/{{archive_name}}.zip target/{{target}}/release/upnotify

archive-all:
just archive-tarball archive-zip

archive: build
just archive-{{archive_type}}
just archive-{{archive_type}}

package-none:
@echo "Nothing to do; specify a package_type"

package-rpm:
#!/usr/bin/env bash
mkdir -p dist/{{target}}
source build/{{target}}.env
nfpm package -p rpm -f <(VERSION={{version}} envsubst < build/nfpm.yaml.tmpl) --target dist/{{target}}/
package-deb:
#!/usr/bin/env bash
mkdir -p dist/{{target}}
source build/{{target}}.env
nfpm package -p deb -f <(VERSION={{version}} envsubst < build/nfpm.yaml.tmpl) --target dist/{{target}}/
linux-packages:
just target=x86_64-unknown-linux-gnu package-deb package-rpm
just target=aarch64-unknown-linux-gnu package-deb package-rpm

package:
just package-{{package_type}}

homebrew-program:

18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use std::thread::sleep;
use std::time::Duration;
use clap::{arg, ArgAction, Command};

use clap::{arg, ArgAction, Command, crate_authors, crate_description, crate_name, crate_version};
use reqwest::blocking::Client;
use reqwest::StatusCode;

enum Result {
StatusCode(StatusCode),
ConnectError(reqwest::Error),
OtherError(reqwest::Error),
None
None,
}

fn main() {
let cli = Command::new("Upnotify")
.version("0.1.0")
.author("Scott Jackson")
.about("Monitors HTTP status changes of a URL")
let cli = Command::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.arg(
arg!(--url <VALUE>).required(true).action(ArgAction::Set)
)
Expand All @@ -24,7 +25,7 @@ fn main() {
let url = cli.get_one::<String>("url").expect("required");
let client = Client::builder()
.danger_accept_invalid_certs(true)
.build().unwrap_or_else(| _result | panic!("Unable to create client!"));
.build().unwrap_or_else(|_result| panic!("Unable to create client!"));
let mut previous_status_option: Result = Result::None;

loop {
Expand Down Expand Up @@ -54,8 +55,7 @@ fn main() {
}
}
}
previous_status_option = if error.is_connect() { Result::ConnectError(error) }
else { Result::OtherError(error) }
previous_status_option = if error.is_connect() { Result::ConnectError(error) } else { Result::OtherError(error) }
}
}
sleep(Duration::from_secs(5));
Expand Down

0 comments on commit fe52683

Please sign in to comment.