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

fail safely on teletype add if the current directory is not a teletype app #72

Merged
merged 1 commit into from
Oct 15, 2020

Conversation

slowbro
Copy link
Contributor

@slowbro slowbro commented Sep 24, 2020

Describe the change

Adds a validate_pwd method to the "add" command that makes sure that a gemspec & directory exists before trying to create the command.

Why are we doing this?

A friendly message is better than a stack trace.

Benefits

This will improve user understanding when accidentally trying to run teletype add outside of the project directory.

Should close #62

Drawbacks

There's no way to directly check that the pwd is actually a teletype app, vs another app that happens to have the same structure. However, that was the case before too - this just covers one edge case.

Requirements

Put an X between brackets on each line if you have done the item:
[...] Tests written & passing locally?
[x] Code style checked?
[x] Rebased with master branch?
[x] Documentaion updated?

lib/tty/commands/add.rb Show resolved Hide resolved
@@ -73,7 +75,7 @@ def execute(input: $stdin, output: $stdout)
cmd_integ_test_file = "#{test_dir}/integration/#{cmd_name_path}_#{test_dir}.rb"
cmd_unit_test_file = "#{test_dir}/unit/#{cmd_name_path}_#{test_dir}.rb"

if !subcmd_present?
unless subcmd_present?

Choose a reason for hiding this comment

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

Style/UnlessElse: Do not use unless with else. Rewrite these with the positive case first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dunno, I wholeheartedly disagree with this. I feel like the reason unless exists is to not have if !... ... @piotrmurach, what's your take?

This isn't directly related to this change, it was just a thing I modified while running though the file - I'll revert it if needbe.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't have a strong preference either way. This change is fine by me.

lib/tty/commands/add.rb Outdated Show resolved Hide resolved
spec/integration/add_spec.rb Outdated Show resolved Hide resolved
spec/integration/add_spec.rb Outdated Show resolved Hide resolved
spec/integration/add_spec.rb Outdated Show resolved Hide resolved
spec/integration/add_spec.rb Outdated Show resolved Hide resolved
@slowbro slowbro marked this pull request as ready for review September 27, 2020 07:37
Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

This will definitely help with user experience. I made a couple of suggestions that may further guide the user, see what you think?

@@ -73,7 +75,7 @@ def execute(input: $stdin, output: $stdout)
cmd_integ_test_file = "#{test_dir}/integration/#{cmd_name_path}_#{test_dir}.rb"
cmd_unit_test_file = "#{test_dir}/unit/#{cmd_name_path}_#{test_dir}.rb"

if !subcmd_present?
unless subcmd_present?
Copy link
Owner

Choose a reason for hiding this comment

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

I don't have a strong preference either way. This change is fine by me.

Comment on lines +280 to +283
def validate_pwd
fail ::TTY::CLI::Error, @pastel.red("This doesn't look like a teletype app directory - are you in the right place?") unless
options[:force] || (@app_path + "lib/#{namespaced_path}").exist?
end
Copy link
Owner

Choose a reason for hiding this comment

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

Since we add commands to lib/app/commands folder, maybe we should check that this location is present? After displaying the error message, we could potentially advise on how to run the command with an example or similar to Rails automatically run teletype add --help ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally was checking that, yes - but it was causing other tests to fail (they set up a fixture that did not make a 'commands' dir). The add command creates the 'commands' directory if it doesn't exist (seemingly):

[katelyn@h test]$ rm -r lib/test/commands
[katelyn@h test]$ teletype add haha
      create  spec/integration/haha_spec.rb
      create  spec/unit/haha_spec.rb
      create  lib/test/commands/haha.rb
      create  lib/test/templates/haha/.gitkeep
      inject  lib/test/cli.rb
[katelyn@h test]$ ls -l lib/test/commands
total 4
-rw-r--r-- 1 katelyn katelyn 332 Sep 28 15:07 haha.rb

..so I don't think the check is necessary.

I like the idea of outputting the 'help' - yeah. I'll add that!

@piotrmurach piotrmurach merged commit 84f0fb7 into piotrmurach:master Oct 15, 2020
@piotrmurach
Copy link
Owner

Thank you! ❤️ My plan is to cut a new release this month.

@slowbro slowbro deleted the issue-62 branch October 16, 2020 00:11
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.

Error with add config
3 participants