Skip to content

Overwrite ability#106

Merged
palkan merged 16 commits into
ruby-next:masterfrom
prog-supdex:overwrite_ability
Mar 30, 2023
Merged

Overwrite ability#106
palkan merged 16 commits into
ruby-next:masterfrom
prog-supdex:overwrite_ability

Conversation

@prog-supdex
Copy link
Copy Markdown
Contributor

@prog-supdex prog-supdex commented Jan 5, 2023

Hello, @palkan!
Please, review my changes

What is the purpose of this pull request?

Support passing --overwrite to CLI for overwriting the original_file

What changes did you make? (overview)

Add the ability to parse --overwrite

Is there anything you'd like reviewers to focus on?

--overwrite ability will work only with --single-version argument. Without the argument --single-version overwrite mode will ignored

Checklist

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation/SUPPORTED_FEATURES.md

Closes #104

Copy link
Copy Markdown
Collaborator

@palkan palkan left a comment

Choose a reason for hiding this comment

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

Thanks!

The implementation looks good to me; let's figure out the tests.

Also:

--overwrite ability will work only with --single-version argument

Can we display a warning if --overwrite is specified but --single-version is missing?

Comment thread spec/cli/nextify_spec.rb Outdated
Comment thread CHANGELOG.md Outdated

## master

## 0.15.4 (2023-01-05)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We do not update versions in PRs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved to ##master

Comment thread README.md Outdated
-o, --output=OUTPUT Specify output directory or file or stdout
--min-version=VERSION Specify the minimum Ruby version to support
--single-version Only create one version of a file (for the earliest Ruby version)
--overwrite Overwrites the original file with one version of --single-version (Works with --single-version)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
--overwrite Overwrites the original file with one version of --single-version (Works with --single-version)
--overwrite Overwrites the original file with one version of --single-version (works only with --single-version)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed to

**works only with --single-version or --rewrite**

Comment thread lib/ruby-next/commands/nextify.rb Outdated
end

def overwrite_original_file?
single_version && overwrite_original_file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can remove single_version from here, since we explicitly check for it presence after parsing

Suggested change
single_version && overwrite_original_file
overwrite_original_file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked.

Comment thread lib/ruby-next/commands/nextify.rb Outdated
exit 2
end

if @overwrite_original_file && !@single_version
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think, we should use single_version? here and also mention --rewriters (as an alternative to --single-version) in the message:

Suggested change
if @overwrite_original_file && !@single_version
if overwrite_original_file? && !single_version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks!

done
Also added spec test for --overwrite and --rewrite args

@prog-supdex prog-supdex requested a review from palkan January 18, 2023 14:40
@prog-supdex
Copy link
Copy Markdown
Contributor Author

Hello @palkan
just a little notification, if you didn`t receive any notifications before :)

Copy link
Copy Markdown
Collaborator

@palkan palkan left a comment

Choose a reason for hiding this comment

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

Thanks for your help!

I'll merge this and apply changes myself.

Comment thread spec/cli/nextify_spec.rb
Comment on lines +353 to +354
old_content = File.read(File.join(__dir__, "dummy", "transpile_me.rb"))
File.write(File.join(__dir__, "dummy", "overwrite", "transpile_me.rb"), old_content)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can prepare a fixture in the before hook instead of restoring it in the after hook. This way, we can avoid duplicating the transpile_me.rb file.

end

if overwrite_original_file? && !single_version?
$stdout.puts "--single-version and --rewrite are missing, --overwrite arg works only with --single-version or --rewrite"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The phrase "--single-version and --rewrite are missing" is confusing; it sounds like we need both

@palkan palkan merged commit 36dd9e7 into ruby-next:master Mar 30, 2023
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.

An option to rewrite file inplace for ruby-next nextify

3 participants