Skip to content

Commit

Permalink
Merge pull request #31 from credmp/develop
Browse files Browse the repository at this point in the history
Version 0.1.9
  • Loading branch information
credmp authored Mar 12, 2023
2 parents a9d0a7a + 746dba0 commit f6efc9b
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 85 deletions.
112 changes: 35 additions & 77 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hed"
version = "0.1.8"
version = "0.1.9"
edition = "2018"
license = "GPL-3.0-or-later"
authors = ["Arjen Wiersma <arjen@wiersma.org>"]
Expand All @@ -16,8 +16,8 @@ readme = "README.md"
name = "hed"

[dependencies]
clap = {version = "3", features = ["derive"]}
color-eyre = "0.5.11"
clap = {version = "4", features = ["derive"]}
color-eyre = "0.6.2"
faccess = "0.2.3"
regex = "1.5.4"
sudo = "0.6.0"
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-03-12 Arjen Wiersma <arjen@wiersma.org>

* src/hostfile.rs: Add an `alias` function to add non-subdomain aliasses to a host entry

2021-10-25 Arjen Wiersma <arjen@wiersma.org>

* src/hostfile.rs: parent domains can be added when a child domain already exists, optimizing the entry.
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ hed delete 127.1.1.1

Will remove the entire record even if there are many aliases defined.

### Add an alias

``` sh
hed alias demo.example.com arjenwiersma.nl
```

Add a non-subdomain alias to a hostname. This is useful when a host (ip) has many different hostnames. Instead of adding an entry for every unique top level domain they can be added as aliasses.

### Testing

Use the `--file` parameter to test the features of `hed` on a file that is not your `hosts` file.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.61.0
1.66.0
15 changes: 12 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{AppSettings, Parser, Subcommand};
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[clap(name = env!("CARGO_PKG_NAME"))]
Expand All @@ -23,7 +23,7 @@ pub enum Commands {
/// List your current hostfile
Show {},
/// Add a host to your hostfile
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[command(arg_required_else_help = true)]
Add {
/// Hostname to add to the hostfile
#[clap(required = true, index = 1)]
Expand All @@ -33,7 +33,7 @@ pub enum Commands {
ip: Option<String>,
},
/// Replace the IP address for a hostname in your hostfile
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[command(arg_required_else_help = true)]
Replace {
/// Hostname of the entry to replace
#[clap(required = true, index = 1)]
Expand All @@ -42,6 +42,15 @@ pub enum Commands {
#[clap(required = true, index = 2)]
ip: Option<String>,
},
/// Alias a name to an existing hostname
Alias {
/// Hostname of the entry to replace
#[clap(required = true, index = 1)]
hostname: String,
/// Alias to add as a hostname
#[clap(required = true, index = 2)]
alias: String,
},
/// Delete a host from your hostfile
Delete {
/// IP or hostname to remove
Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum ApplicationError {
#[error("An entry exists with the hostname, but with a different IP:\n{0}")]
HostnameAlreadyInUse(String),

#[error("No such hostname available in the hostfile: {0}")]
HostnameDoesNotExist(String),

#[error("Could not add host, no parent domain to resolve it. This means that no parent domain exists for the given hostname, try adding it with an IP address, it will be the first entry for this host.")]
NoParentDomain(),

Expand Down
Loading

0 comments on commit f6efc9b

Please # to comment.