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

Introduces version command to retrieve shards current version #148

Merged
merged 1 commit into from
Feb 9, 2017
Merged

Introduces version command to retrieve shards current version #148

merged 1 commit into from
Feb 9, 2017

Conversation

luislavena
Copy link
Contributor

Sometimes is useful to obtain the current version string of the library/project you're working on, either to help you determine if was bumped (when preparing for a new release) or when integrating it within the library's VERSION constant (through macros).

This change introduces version command for such purpose, allowing you retrieve from current directory (by default) or be able to provide a different path.

Usage example

module Foo
  VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
end

Resulting in a Foo::VERSION matching the version defined in shard.yml.

Fixes #147

end

def run(*args)
puts spec.version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use print so that chomp doesn't have to be used in the macro?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess because you'll get borked output using cli.

Copy link
Contributor Author

@luislavena luislavena Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RX14 for the reason given by @Sija:

$ shards version
0.3.7
$

Using print breaks the resulting prompt:

$ shards version
0.3.7$

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... My prompt seems to fix that for me. Never mind then.

@luislavena luislavena changed the title Introduces version to retrieve shards current version Introduces version command to retrieve shards current version Feb 5, 2017
Copy link
Contributor

@ysbaddaden ysbaddaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Just a few tiny details, and are you testing that the command will search up the directory tree until if finds a spec file?

module Commands
class Version < Command
def self.run(path, *args)
# look up for `shard.yml` in given directory or up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract this part as a method? For example lookup_spec(path) : String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking on that, but that would be a another class method, so perhaps is better move that to a helper instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, private class method is fine. There is no other usage of it for now.

break if File.exists?(shard_file)

previous = current
current = File.expand_path("..", current)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about leveraging File.dirname?

@luislavena
Copy link
Contributor Author

are you testing that the command will search up the directory tree until if finds a spec file?

Yes, see test_version_within_directory test.

Will get those changes done soon.

Thank you.

Sometimes is useful to obtain the current version string of the
library/project you're working on, either to help you determine if
was bumped (when preparing for a new release) or when integrating
it within the library's `VERSION` constant (through macros).

This change introduces `version` command for such purpose, allowing
you retrieve from current directory (by default) or be able to
provide a different path.

Usage example

    module Foo
      VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
    end

Resulting in a `Foo::VERSION` matching the `version` defined in
`shard.yml`.

Fixes #147
@luislavena
Copy link
Contributor Author

@ysbaddaden changes pushed, waiting for Travis OSX to confirm.

Cheers.

@ysbaddaden ysbaddaden merged commit 10ed3ea into crystal-lang:master Feb 9, 2017
@ysbaddaden
Copy link
Contributor

Thank you!

@luislavena luislavena deleted the add-version-command branch February 9, 2017 18:19
veelenga added a commit to crystal-ameba/ameba that referenced this pull request Dec 26, 2017
veelenga added a commit to crystal-ameba/ameba that referenced this pull request Dec 26, 2017
f-fr pushed a commit to f-fr/shards that referenced this pull request Jan 2, 2021
Introduces `version` command to retrieve shards current version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants