Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Implemented request-body data insertion through text-editor #45

Merged
merged 9 commits into from
Dec 21, 2021

Conversation

devblin
Copy link
Contributor

@devblin devblin commented Dec 7, 2021

Implements #41

For methods with request body, this update now allows user to insert request body data through editor.
For example:

  • Currently, this is what we do to add request body:
    $ hopp-cli post https://reqres.in/api/users/2 -c js -b '{"name": "morp","job": "zion resident"}'
  • Now, we can also use -e flag, indicating request data insertion through text-editor:
    $ hopp-cli post https://reqres.in/api/users/2 -c js -e

@devblin devblin marked this pull request as draft December 7, 2021 18:27
Copy link
Contributor

@gbmor gbmor left a comment

Choose a reason for hiding this comment

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

There are some idioms that were missed that are typically used in Go, a possibility for filesystem pollution with stray files, a possible runtime panic, some extra allocations (from redundant type conversion), and one usability concern.

The major thing is the runtime panic. 😄

methods/basic.go Show resolved Hide resolved
methods/basic.go Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
Copy link
Contributor

@gbmor gbmor left a comment

Choose a reason for hiding this comment

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

Realized I left this out of my initial review, an important error return value was discarded.

methods/basic.go Outdated Show resolved Hide resolved
Copy link
Contributor

@athul athul left a comment

Choose a reason for hiding this comment

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

Hey @devblin the PR seems fine. Please address the changes and feedback given by @gbmor and me 🤝

methods/basic.go Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
methods/basic.go Outdated Show resolved Hide resolved
@devblin devblin marked this pull request as ready for review December 8, 2021 08:27
@devblin
Copy link
Contributor Author

devblin commented Dec 8, 2021

@athul I have updated the changes, and I was getting some conflicts, I have resolved the conflicts in local with changes from master and I am getting error here:

body, err = io.ReadAll(os.Stdin)
as undefined: io.ReadAll, so should I updated it within this PR ?

@gbmor
Copy link
Contributor

gbmor commented Dec 8, 2021

@devblin change that to ioutil.ReadAll(...) ... it's related to my other PR which was to bring hopp-cli up to Go1.16, and that function didn't exist before 1.16

@devblin
Copy link
Contributor Author

devblin commented Dec 9, 2021

@devblin change that to ioutil.ReadAll(...) ... it's related to my other PR which was to bring hopp-cli up to Go1.16, and that function didn't exist before 1.16

I updated it within my last commit 👍🏽 .

@athul
Copy link
Contributor

athul commented Dec 15, 2021

@gbmor I request another round of review 🙈

@athul
Copy link
Contributor

athul commented Dec 15, 2021

@devblin please add the required changes to the readme too ✨

Copy link
Contributor

@gbmor gbmor left a comment

Choose a reason for hiding this comment

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

Looks pretty much good to me, as far as the code goes. I had one question about calling notepad which I don't know the answer to because I don't have a windows machine to test it on, and I've only ever written software targeting Linux/OpenBSD/FreeBSD, but I tagged it in the review. @athul maybe you know? Or have a windows machine to test it on?

Also, maybe add a blurb in the readme about using -e and how it checks $EDITOR then falls back to nano or notepad?

if currentOs == "linux" || currentOs == "darwin" {
editor = "nano"
} else if currentOs == "windows" {
editor = "notepad"
Copy link
Contributor

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 windows machine to test this, and I haven't really used windows since 2006-2007 so I'm just guessing here: but will this still find notepad without the file extension, or should it be notepad.exe?

Copy link
Contributor Author

@devblin devblin Dec 16, 2021

Choose a reason for hiding this comment

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

@gbmor I have tested it on windows machine too. And as exec.LookPath() function searches for executable files only, we can use both notepad and notepad.exe

Copy link
Contributor

Choose a reason for hiding this comment

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

@devblin OK cool! Good to know. I'll remember that for when I have to target Windows in the future 👍

@devblin
Copy link
Contributor Author

devblin commented Dec 16, 2021

@devblin please add the required changes to the readme too ✨

Updated README 👍🏽

Copy link
Contributor

@athul athul left a comment

Choose a reason for hiding this comment

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

Just some small stuff I think would be good, you can accept or ignore it completely. Anyways looks good to me. Sorry for taking forever to merge this. Was a bit tied up with some stuff

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@devblin
Copy link
Contributor Author

devblin commented Dec 18, 2021

I missed to mention that in Windows the print statement mentioned below wasn't properly color-encoding the out in terminal.

hopp-cli/cli.go

Line 172 in 8e85342

fmt.Println(out)

Instead, as mentioned in https://github.com/fatih/color/blob/master/doc.go#L89 , we should use
fmt.Fprintf(color.Output, out)

@athul
Copy link
Contributor

athul commented Dec 19, 2021

I missed to mention that in Windows the print statement mentioned below wasn't properly color-encoding the out in terminal.

hopp-cli/cli.go

Line 172 in 8e85342

fmt.Println(out)

Instead, as mentioned in https://github.com/fatih/color/blob/master/doc.go#L89 , we should use
fmt.Fprintf(color.Output, out)

Okay. Haven't had the chance to test everything on windows(I don't have a windows machine either). It'd be great if you could push that too

@devblin
Copy link
Contributor Author

devblin commented Dec 19, 2021

Done

@athul
Copy link
Contributor

athul commented Dec 21, 2021

I guess this is ready to be merged. Thank you @devblin and @gbmor 🎉 🎉

@athul athul merged commit f3d27cf into hoppscotch:master Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants