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

configuration with command-line arguments #14

Open
X1011 opened this issue Oct 5, 2015 · 13 comments
Open

configuration with command-line arguments #14

X1011 opened this issue Oct 5, 2015 · 13 comments

Comments

@X1011
Copy link
Owner

X1011 commented Oct 5, 2015

I'm thinking about changing how the configuration is specified. Rather than having users modify the script or set environment variables, the script would take additional command-line arguments. I would do this for deploy_directory, deploy_branch, and repo. I would eliminate default_username and default_email and just require the user to have git sufficiently configured beforehand.

I'm considering a syntax like this: deploy.sh [<options>] [<directory> [<branch> [<repository>​]]]

pros:

  • the script doesn't need to be modified, so it can be shared across projects, installed as a package, and write protected
  • no polluting of environment variables, no chance of name collisions
  • makes apparent that a relative deploy_directory is relative to the current working directory, eliminating the need to mention this in the readme

cons:

  • complicates ad-hoc deployments not using the defaults, as you would now have to either remember to include the arguments every time or create a wrapper script
  • having 3 positional arguments, it may be hard to remember which is which
  • will probably complicate argument parsing

questions:

  • which arguments should be positional or named? (e.g., should we do something like this instead?: deploy.sh [-d <directory>] ...)
  • which arguments should still have defaults or be required?

Let me know if you think this is a good or bad idea.

@LeonardDrs
Copy link

Hi X1011.

I recently came across your script and it suits me -almost- well.
I like flexibility and think this enhancement is a good idea since I added my own code to yours in order to use additional command-line arguments.

My syntax is currently like this deploy.sh [<directory> [<branch> [<repository>​]] [<options>]

About your cons:

  • Agree, but actually I'm using a wrapper as I need to do others things
  • We could use a deploy.hs -h to display the syntax.
  • Yeah it'll.

About your questions:

  • I kinda like it when arguments are positional, but it's up to you.
  • My guess would be using default values for the 3 arguments. dist, gh-pagesand origin.

Cheers

@matro
Copy link
Contributor

matro commented Dec 8, 2015

I think this is a fantastic idea! I'd actually started writing a fork of this script to remove configuration bits (and do some other stuff that probably doesn't matter), but this makes me want to drop my fork and come back to this project.

I agree with @LeonardDrs about the defaults for those three arguments; they're totally sane.

[<directory> [<branch> [<repository>​]] order makes sense to me too. I don't have a strong opinion whether [<options>] should come before or after the positional stuff, though I tend to prefer tools that work either way (see rsync). It'd make args-parsing more complicated, but usage more flexible and friendly to human foibles.

Here're a couple of ideas that might make things even more flexible, robust, and mitigate some of the cons for ad-hoc usage:

  1. Add sourceing a .env file to set variables, and a --config option to specify an alternate file name.
  2. Set variables in this logical order, where whatever the most "specific" setting (higher number in this list) wins:
    1. Script's default (yay for assuming nothing!)
    2. Environment variables (support current assumptions about env vars)
    3. .env file (or the vars-file specified on the command-line) if this was implemented.
    4. Command-line's [<directory> [<branch> [<repository>​]] strings.

This'd let users run the script with the existing "the script's defaults work for me" and "my environment vars are fine" assumptions, plus let "project-specific" environments and ad-hoc command-line'ing override/replace the more generally-scoped vars.

Would totally make sense to punt "add support for .env files" to another issue (and I'd be happy to try implementing it)... but I figured it'd make sense bringing up here first.

@X1011
Copy link
Owner Author

X1011 commented Dec 9, 2015

@matro, cool, that all sounds good. Have at it!

matro pushed a commit to matro/git-directory-deploy that referenced this issue Dec 10, 2015
 1. If `.env` exists in the current path, it gets sourced.
 2. If `-c $FILE` or `--config-file $FILE` is specified, `$FILE` gets sourced.

Values set earlier get overriden by those set later.

Fixes part of X1011#14.
matro pushed a commit to matro/git-directory-deploy that referenced this issue Dec 10, 2015
 1. If `.env` exists in the current path, it gets sourced.
 2. If `-c $FILE` or `--config-file $FILE` is specified, `$FILE` gets sourced.

Values set earlier get overriden by those set later.

Fixes part of X1011#14.
@matro
Copy link
Contributor

matro commented Dec 11, 2015

I think there are pull requests for all three aspects of this now.

@matro
Copy link
Contributor

matro commented Dec 11, 2015

I'm game for trying to get the args-parsing into its own function with test coverage as well... should we take that to a separate issue/PR, or keep this thread going?

@X1011
Copy link
Owner Author

X1011 commented Dec 12, 2015

I'm gonna say keep this thread going, as all the PRs are in support of this goal. Then, the last PR out can close this issue.

@matro
Copy link
Contributor

matro commented Dec 16, 2015

So I've learned a bit about writing bats tests, and have some new test files added to both PRs. I put them in tests/ to try to keep the project root clean, but haven't done anything to existing test files or the watch script yet.

Should I pop my new test files up to the project root, or would it make sense to put all tests in the tests folder?

@X1011
Copy link
Owner Author

X1011 commented Dec 16, 2015

I think you have too many tests now. Most of the variables are being parsed the exact same way, so the tests aren't testing unique behaviors, and the extra tests aren't adding much value, but they complicate maintenance and onboarding, increase run time, etc.
I recommend:

  • 5 tests for append_hash, checking that it gets overridden for each progressively higher-priority config source
  • a test for --message, since it seems you've found an issue with messages containing spaces, and
  • whatever tests are needed for the positional args.

The rest i think we can do without.

That may change how you want to organize the tests into files, but I'm gonna say once we end up with 4 or more .bats test files in the root, then let's put them in their own folder. And don't forget to update circle.yml so that the CI server runs them.

Also, i don't know if you've noticed the 'pseudo groups' i've created using clever whitespace in the test names. I was going for an RSpec/Mocha-style format. What do you think, is it worth continuing that style?

@matro
Copy link
Contributor

matro commented Dec 16, 2015

Okay, I'll pair down and consolidate things a bit. This is my first time actually writing unit tests of any kind, so I'm kind of learning as I go. I was also trying to tease out any more weird cases like append_hash; I don't trust that my mental model matches the code yet.

I did notice the 'pseudo groups' thing you did. I think it's definitely worth continuing. I haven't tried to follow it so far because I'm not how to logically group this stuff yet. Definitely makes more legible output.

@matro
Copy link
Contributor

matro commented Dec 16, 2015

Got another stab a #19. Fingers crossed there now.

I'll try to make -c not require being first over in #20, I think. Feels like the problem kind of related to positional args, to me.

And I've started another branch to try fixing the issue with -m and spaces.

@matro
Copy link
Contributor

matro commented Dec 18, 2015

So #20 looks good to me now. Things turned out pretty simple, once some of this other stuff was done and I had some clue about what I'm doing.

I'm tempted to take the "make -c not require being first" to its own PR (and maybe separate issue?). I don't have any bright ideas about how to make this happen yet, either.

@X1011
Copy link
Owner Author

X1011 commented Dec 18, 2015

yea, i say take -c to a separate issue (or just a PR, if you're gonna have one soon); it wasn't even part of the original plan.

@jessevdp
Copy link

jessevdp commented Oct 2, 2017

Did these command line arguments ever get implemented? I'm trying to setup automated deployment of a subfolder to a gh-pages branch using travis-ci and decided to use their script deployment feature.

I've defined the following script:

./deploy.sh ./app gh-pages https://$GITHUB_TOKEN@github.com/USER/REPO.git
# Where 'USER' and 'REPO' are filled in ofc 😇
# $GITHUB_TOKEN is available as a secure travis env variable

As you can see it's following the [<directory> [<branch> [<repository>​]] order of arguments here.

Here's the output:

Deploy directory 'dist' does not exist. Aborting.
Script failed with status 1

As you can see, even though I've specified ./app as the folder I want to deploy as a command line argument the script seems to be testing for the /dist folder.


I'm unsure, there seems to be a pull request (#20) that's ready to go — but it's open 🤔 and hasn't been touched since 2015.

I'm gonna add a question in here

The README file was a little vague to me. Would it be possible to just set env variables and the script would pick up on them? I'm talking about these variables:

GIT_DEPLOY_DIR
GIT_DEPLOY_BRANCH
GIT_DEPLOY_REPO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants