#bluesky #turso #linkedin #command-line-interface #cli

bin+lib musket

Musket is a command line interface to send a URL to several destinations

9 releases (breaking)

new 0.15.1 Dec 20, 2024
0.14.0 Dec 11, 2024
0.12.0 Nov 30, 2024

#537 in Command line utilities

Download history 154/week @ 2024-11-18 469/week @ 2024-11-25 22/week @ 2024-12-02 270/week @ 2024-12-09

915 downloads per month

MIT license

29KB
405 lines

Musket

Musket is a command line interface to send a URL to several destinations. Each destination handle the URL depending the nature of the destination, for example, Bluesky destination post the URL in the user's feed, LinkedIn destination publish the link in the user profile and Turso destination stores the URL in Turso Service (a SQLite database SaaS).

Usage

1.- Install

cargo install musket

2.- Create the configuration file

To create the configuration file, execute:

$ musket init

Musket uses a configuration file named config.toml. This file is placed in the directory musket inside the users's home. This home depends of the operating system:

The musket init command will display the full path to the configuration file.

3.- Configure the destinations

All destinations have to be configured from the configuration file.

Bluesky

Before sending a URL to Bluesky destination you must:

  1. Create a Bluesky account. For a while, Musket only suports the Bluesky Social provider.
  2. Fill the bluesky section in the Musket configuration file. You must provide:
    • the identifier is the account's username or email.
    • the password of the account.
    • share_commentary is the text that will be shown in the post along the link.

LinkedIn

Before sending a URL to LinkedIn destination you must:

  1. Create a LinkedIn Application with the Share on LinkedIn and Sign In with LinkedIn using OpenID Connect products added to the application.
  2. Create an access token with the email, openid, profile, w_member_social permissions.
  3. Get the author identifier (doing a request to the userinfo endpoint using the access token).
  4. Fill the linkedin section in the Musket configuration file. You must provide:
    • the token used as a bearer authentication.
    • the author identifier.
    • share_commentary is the text that will be shown in the post along the link.
    • visibility, can be "PUBLIC" or "CONNECTIONS".

Turso

Before sending a URL to Turso destination you must:

  1. Create a Turso account.
  2. Create a Turso Database.
  3. Create a Table with the following schema:
CREATE TABLE links (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  url TEXT,
  tags TEXT,
  created DATETIME
);
  1. Fill the turso section in the Musket configuration file. You must provide the database url and the turso token.

4.- Sending a URL

$ musket fire --url <URL> --destination <DESTINATION> --tags <tags>

For example:

$ musket fire --url wikipedia.org --destination bluesky,linked-in,turso --tags one,two,three

or

$ musket fire --url wikipedia.org -d bluesky -d linked-in -d turso -t one -t two -t three

Run musket -h to get the details of each subcommand and arguments.

Contributing

Requirements

Last stable Rust toolchain. Use Rustup to install it.

Guidelines

Adding destinations

To add new destinations you must follow the next steps:

Info: Use the existing destinations code files as a source of information.

1. Define the configuration

In the config.rs file, add a struct to define the new destination configuration.

Info: Add the struct in alphabetical order.

For example:

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct TursoConfiguration {
    pub url: String,
    pub token: String,
}

Add a field in the Configuration struct with the destination as a name and the destination configuration as a type:

Info: Add the field in alphabetical order.

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct Configuration {
    pub bluesky: BlueskyConfiguration,
    pub linkedin: LinkedinConfiguration,
    pub turso: TursoConfiguration,
    // Add the new destination configuration
}

2. Create a module

Create a file with the name of the new destination inside destinations folder.

2.1. Develop the destination logic

Add a public struct with the fields needed to configure the destination. This fields must be pub.

Add all the login needed to send the URL, and the tags, to the destination in the Destination trait implementation.

2.2. Handle the errors

In the errors.rs file, add the new destination as a variant of the enum DestinationError and add the new destination in the pattern matching in the Display trait implementation of the DestinationError .

Back in the module file, implement the From trait for DestinationError.

2.4. Enable the module

Once created, add the new module as a public module in the destination module inside the mod.rs file.

For example:

pub mod bluesky;
pub mod linkedin;
pub mod turso;

Info: Add the modules in alphabetical order.

3. Manage new destination from the CLI

In the cli.rs file, add the new destination as a variant of the enum Destinations.

pub enum Destinations {
    All,
    Bluesky,
    LinkedIn,
    Turso,
    // Add here the new destination
}

Info: Add the modules in alphabetical order.

4. Create a Command

Create a file with the name of the new destination inside commands folder.

This file must implement a function named execute in charge of perform the sending of the URL (and tags if needed) to the destination.

Once created, add the new module as a public module in the commands module inside the mod.rs file.

For example:

pub mod bluesky;
pub mod linkedin;
pub mod turso;

5. Manage new destination from the lib

In the ['lib.rs](./src/lib.rs) file, add the new destination as a pattern matching of the Firecommand, and add a call to the command created above. Remember to add the command to theDestinations::All` match.

For example:

Destinations::All => {
    bluesky::execute(&cfg, &url, &vector_of_tags).await?;
    linkedin::execute(&cfg, &url, &vector_of_tags).await?;
    turso::execute(&cfg, &url, &vector_of_tags).await?;
}
Destinations::Bluesky => {
    bluesky::execute(&cfg, &url, &vector_of_tags).await?;
}
Destinations::LinkedIn => {
    linkedin::execute(&cfg, &url, &vector_of_tags).await?;
}
Destinations::Turso => {
    turso::execute(&cfg, &url, &vector_of_tags).await?;
}

Info: Add the destinations in alphabetical order.

6. Update the documentation

In the README.md file, add a documentation about how to configure the new destination inside the section Configure the destinations.

Dependencies

~13–26MB
~380K SLoC