Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider building and packaging the Shlink CLI as a static binary #1527

Open
onedr0p opened this issue Aug 29, 2022 · 4 comments
Open

Consider building and packaging the Shlink CLI as a static binary #1527

onedr0p opened this issue Aug 29, 2022 · 4 comments
Labels

Comments

@onedr0p
Copy link

onedr0p commented Aug 29, 2022

Summary

Hi 👋🏼

It would be great if the shlink CLI (https://shlink.io/documentation/command-line-interface/entry-point/) could be written as such that it would be compiled and packaged as a static binary.

The main benefits would be for the CLI to be packaged for various OS distributions. Imagine being able to run brew install shlink-cli or pacman -S shlink-cli or whatever.

I don't know if this would be possible in its current form and maybe a Go / Rust based CLI tool to interact with the shlink API might be better suited for static binaries.

Anyways, thanks for hearing me out.

@onedr0p onedr0p changed the title Consider building an packaging the shlink CLI as a static binary Consider building and packaging the shlink CLI as a static binary Aug 29, 2022
@onedr0p
Copy link
Author

onedr0p commented Aug 29, 2022

For a bit more clarity, I am trying to script the creation of short URLs on the CLI. My shlink is running on another server, is it true that the current CLI needs to ran where the app is deployed? If true then it seems the only way to interact with shlink on the CLI is via the REST API with curl or something.

@acelaya
Copy link
Member

acelaya commented Aug 29, 2022

Unfortunately yes. Shlink's CLI, the way it is created right now, does not interact with Shlink's API, but its internals, so it cannot be extracted as it is into a separated tool.

Also, there's no way to statically build a binary with the technologies currently used for Shlink.

If you are an expert on go/rust or similar, it would be amazing to have such tool. I would be able to support on the API integration as much as needed.

@onedr0p
Copy link
Author

onedr0p commented Aug 29, 2022

It would be nice to have such a project under the shlinkio org even if you are the maintainer or not. I would love to contribute if I had free time. I'll add this to the long list of projects on my TODO 😄

@acelaya acelaya added this to the 3.4.0 milestone Sep 17, 2022
@acelaya acelaya added this to Shlink Sep 25, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Sep 25, 2022
@acelaya acelaya removed the status in Shlink Sep 25, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Dec 3, 2022
@acelaya acelaya removed this from the 3.4.0 milestone Dec 4, 2022
@hashworks
Copy link

hashworks commented Jan 9, 2023

If you just need a CLI tool to create, list and delete short URLs, this will do just fine:

SHLINK_HOST=https://example.com
SHLINK_API_KEY=foobar

shlink () {
	BASE_URL="${SHLINK_HOST}/rest/v3/short-urls"
	if [[ "$1" == "delete" ]] && [[ -n "$2" ]]
	then
		curl -s -X 'DELETE' -H 'accept: application/problem+json' -H "X-Api-Key: ${SHLINK_API_KEY}" \
			"${BASE_URL}/${2}" | \
			jq
	elif [[ -z "$1" ]]
	then
		curl -s -X 'GET' -H 'accept: application/json' -H "X-Api-Key: ${SHLINK_API_KEY}" \
			"${BASE_URL}?orderBy=dateCreated-DESC" | \
			jq -r '.shortUrls.data[] | .shortUrl + " -> " + .longUrl'
	elif [[ "$1" != "help" ]] && [[ "$1" != "--help" ]]
	then
		curl -s -H "Content-Type: application/json" \
			"${BASE_URL}/shorten?apiKey=${SHLINK_API_KEY}&format=txt&longUrl=${1}"
		echo ""
	else
		echo "shlink"
		echo "shlink <target-url>"
		echo "shlink delete <uuid>"
		return 2
	fi
}

Just put it in your .bashrc or whatever. Needs jq and curl.

 % shlink https://example.com/test
https://example.com/NuyIj
 % shlink https://example.com/test2
https://example.com/lPKI5
 % shlink
https://example.com/lPKI5 -> https://example.com/test2
https://example.com/NuyIj -> https://example.com/test
 % shlink delete NuyIj
 % shlink
https://example.com/lPKI5 -> https://example.com/test2

@acelaya acelaya moved this from Todo to In Progress in Shlink Jan 3, 2024
@acelaya acelaya moved this from In Progress to Todo in Shlink Jan 3, 2024
@acelaya acelaya changed the title Consider building and packaging the shlink CLI as a static binary Consider building and packaging the Shlink CLI as a static binary Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

3 participants