Find version of a module - go

We are working with Go modules. I want in a CLI to get the specific version of a module. Is it possible?
If you are curious, the reason is that I want to add the following generate command:
//go:generate go run github.com/golang/mock/mockgen -source="$GOPATH/pkg/mod/mymodules.com/mymodule#${VERSION}/module.go" -destination=module_mock.go
So I need to somehow get the version

Basics:
go list -m all — View final versions that will be used in a build for all direct and indirect dependencies
go list -u -m all — View available minor and patch upgrades for all direct and indirect dependencies
Example:
To get the version of a specific module, let's say golang.org/x/text
go list -m all | grep golang.org/x/text | awk '{print $2}'
or
go list -u -m all | grep golang.org/x/text | awk '{print $2}'
So, the general way:
go list -u -m all | grep <module-name> | awk '{print $2}'

Late but worth to mention, if you want to check the all available versions of a specific module:
go list -m -versions <module_name>
Like:
go list -m -versions github.com/user/module-name

This command will get the version of go that's used in a project.
[$]> grep -m 1 go go.mod | cut -d\ -f2
That'll output a version like 1.18.

Related

Finding latest version of anaconda automatically from bashrc

I'm trying to create a code which will fetch the latest version of anaconda and install it.
Currently we can do this to install the latest version:
mkdir tmp
cd tmp
wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh
I want the script to be more generalized such that the code would automatically find the latest version of anaconda, download the shell script file and install it.
You can use this to get the latest version:
wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'| \
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p'
uniq |\
sort -r |\
head -1
This solution works only for those versions that use the year format (e.g. 2020-07), but since the latest version will presumably be of that format that should be fine.
Some explanation:
wget to fetch the contents of the archive page, which gives us the HTML content containing all the download URLs. -q quiets the output, -O- prints to stdout. Alternatively, you can use curl -s to the same effect.
grep 'Anaconda3' gives us the lines containing Anaconda, which contain the download links.
Use sed to select the version strings from the download links, e.g. 2020-11. That gives you a list of all versions (of the format YYYY-MM).
Sort that lists and select the first entry, which is the latest version.
Use the version in the rest of your script and you are done. A complete solution would be:
version=$(wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'|\
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p' |\
uniq |\
sort -r |\
head -1)
wget "https://repo.anaconda.com/archive/Anaconda3-$version-Linux-x86_64.sh"
I'm sure fetching the latest version could be made more efficient, but this should be sufficient for your use case.

Command to show latest Drupal 8 version available

I am looking for a way to display the latest Drupal 8 version available for download in a shell command.
I currently have this command which shows the current version available for the site installed:
drush core-status drupal-version | tr -d "Drupal version : "
This returns
'8.6.13'
I am now looking for a way to obtain the latest version number available to date which is
'8.6.15'
You used to be able to use
drush pm-releases drupal
to get this information. This post mentions using a feed to help get this information:
https://drupal.stackexchange.com/questions/133925/find-latest-drupal-version-number
One way of doing it:
curl -w "%{url_effective}\n" -I -L -s -S https://www.drupal.org/8/download -o /dev/null | awk -F'/' '{print $7}'
composer show -l drupal/core | grep ^latest
See documentation at: https://getcomposer.org/doc/03-cli.md#show
Another option is:
composer outdated -a -D|grep ^drupal/core
You can probably get the complete list of available versions with:
drush php:eval '
$ver = array_keys(
( update_get_available(TRUE) )["drupal"]["releases"]
);
asort($ver);
echo implode("\n",$ver),"\n";
'

How to exclude or skip specific directory while running 'go test' [duplicate]

This question already has an answer here:
Running tests and skipping some packages
(1 answer)
Closed 3 years ago.
go test $(go list ./... | grep -v /vendor/) -coverprofile .testCoverage.txt
I am using the above command to test the files but there is 1 folder with the name "Store" that I want to exclude from tests. How it can be done?
You're already doing it:
$(go list ./... | grep -v /vendor/)
The grep -v /vendor/ part is to exclude the /vendor/ directory. So just do the same for your Store directory:
go test $(go list ./... | grep -v /Store/) -coverprofile .testCoverage.txt
Note that excluding /vendor/ this way is not necessary (unless you're using a really old version of Go). If you are using an old version of Go, you can combine them:
go test $(go list ./... | grep -v /vendor/ | grep -v /Store/) -coverprofile .testCoverage.txt

command to run latest java jar in a directory

I'm currently running my jars with $ java -jar /path/to/fooproject-x.y.z-standalone.jar where x.y.z is the version. I could've sworn I saw a very simple, slightly modified version of this command that just runs the highest version jar in the directory and I can't for the life of me find it again. This is a real thing right?
Please consider this command:
$ ls *.jar | sort -t- -k2 -V -r | head -1
I'm specifying the separator and set of keys to sort on. And use pipe to find the latest JAR with head command. You can assign this way:
LATEST_VERSION=$(ls foo*.jar | sort -t- -k2 -V -r | head -1)
And run the jar with any params you need.

How to list any gems that aren't dependencies (i.e., sort of like `brew leaves` in Homebrew)

I'm aware of gem dependency as a means to investigate a dependency graph, but I'm looking for something a little more straightforward. I only want to list gems that aren't dependencies of other gems.
In Homebrew, you can accomplish something similar with brew leaves - this lists packages that aren't dependencies of other packages. I mention this in case it's helpful in understanding what I'm trying to accomplish.
I've made a small shell script for that:
#!/bin/sh
GEMS_FILE=`mktemp`
DEPENDENCIES_FILE=`mktemp`
gem list -l | sed 's/ (.*//' | sort > $GEMS_FILE
cat $GEMS_FILE | xargs -n1 gem dependency -l --pipe | sed 's/ --version.*//' | sort -u > $DEPENDENCIES_FILE
comm -23 $GEMS_FILE $DEPENDENCIES_FILE
rm -f $GEMS_FILE $DEPENDENCIES_FILE
Also in a Gist form: https://gist.github.com/astyagun/290b783045afffb8190a0c75ab76d0fa
Sounds like you're looking for the gem list command.
If you're looking for gem help you can just run gem --help.

Resources