Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Last active August 29, 2015 14:22
Show Gist options
  • Save kevinohara80/4db783e27e81c2ba01f3 to your computer and use it in GitHub Desktop.
Save kevinohara80/4db783e27e81c2ba01f3 to your computer and use it in GitHub Desktop.
dmc globbing semantics proposal

dmc globbing semantics proposal

The goal of dmc is to provide a "file-sytem-like" command line api for salesforce.com metadata deploys and retrieves. The original goal was to allow simple globbing patterns to select the metadata to deploy as well as the metadata to retrieve. It was looking something like this...

Deploys:

$ dmc deploy src/classes/* 
$ dmc deploy src/**/*
$ dmc deploy src/pages/Module* src/classes/Module*

Retrieves (the exact same patterns):

$ dmc retrieve src/classes/*
$ dmc retrieve src/**/*
$ dmc deploy src/pages/Module* src/classes/Module*

The globbing problem

When you pass a raw globbing pattern as a command line argument, most *nix shells will glob that pattern for you, match the files, and pass the matched files to your program. For dmc this works most of the time for deploys, and it kind a deal-killer for retrieves.

Deploy Problems

When I say it works most of the time for deploys, that's because the files that you want to deploy must actually be present in the src directory. Each shell handles globbing differently though. For example, you'd really want a glob like src/**/* to match all files and have that pattern traverse through subdirectories using globstar. However, globstar is not a default in bash so you'd have to modify your .bash_profile or .bashrc to turn this on by default, otherwise, you'll only match directories that are a direct child of src and no subdirectories would be expanded.

Retrieve Problems

The globbing issue is a deal killer for retrieves. If we let the shell environment process that glob pattern, we'd only ever be able to retrieve the files that are currently in our local src directory. We want to be able to do src/**/* here if we wanted to get all metadata for an org. dmc really needs to take the raw globbing pattern and handle it completely differently. I have some code that would take the pattern and process it over a retrieved index of metadata.

Possible Solutions

Here is where I need some help. There are several ways to make this work and I'd like to know what you think would be the best solution. I'm also open to other solutions.

Again the goal is to keep the deploy and retrieve api feeling very similar. Since raw globbing patterns won't really work at all for retrieves, one simple solution is to enforce that globs are passed to dmc in a way that they won't be expanded by the shell. Here are some possibilities.

Using Quotes:

This is the simplest solution as this tells the shell not to process the glob. This would even mean that you could still use un-quoted glob patterns but the user would just need to understand how their current shell would handle it. dmc still treats the arguments as globs even if the shell has already expanded them.

$ dmc deploy 'src/**/*'
$ dmc deploy 'src/classes/* src/pages/*'
$ dmc retrieve 'src/**/*'
$ dmc retrieve 'src/classes/*' 'src/pages/*'

Bracket (array-like):

This is more verbose, but would feel very familiar to javascript developers

$ dmc deploy ['src/**/*']
$ dmc deploy ['src/classes/*', 'src/pages/*']
$ dmc retrieve ['src/**/*']
$ dmc retrieve ['src/classes/*', 'src/pages/*']

Alias instructions:

This one sucks but you could just provide setup instructions on how to alias the dmc binary to turn off globbing so that dmc could just handle it. This would be different for each shell. I also have no idea how any of this would work in Windows.

Other Suggestions

Any other ideas here?

@pfeilbr
Copy link

pfeilbr commented Jun 12, 2015

You could also add an explicit flag to turn globbing on or off like http://curl.haxx.se/docs/manpage.html#-g.

@kevinohara80
Copy link
Author

You could also add an explicit flag to turn globbing on or off like http://curl.haxx.se/docs/manpage.html#-g.

@pfeilbr I actually don't think that's possible. The problem is that your shell is going to process the glob before it executes your script. There's really no way to do it at runtime. The only option is to alias the command so that it runs something like set -f;dmc in place of just dmc (bash example).

@jondavis9898
Copy link

+1 for Bracket (array-like).

  1. Allows for future cmd line args to be added to enhance functionality
  2. Includes the quotes option which handles situations where there are spaces in path names

One other option, although I don't really like it but worth mentioning, is to use a different globstar pattern replacing the asterix with another token (e.g. /src/!!/!). Even with this, I still would vote for bracket approach.

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