Skip to content

Commit ad1e72e

Browse files
committed
Adds comment options for command line tool
1 parent e670de8 commit ad1e72e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

tool/sass2scss.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstring>
55
#include <sstream>
66
#include <iostream>
7+
#include <stdlib.h>
78

89
#include "sass2scss.h"
910

@@ -18,12 +19,25 @@ int main (int argc, char** argv)
1819
// set by command line
1920
int pretty = 0;
2021

22+
// bitwise options
23+
// set by command line
24+
int options = 0;
25+
2126
// process command line arguments
22-
for (int i = 0; i < argc; ++i)
27+
for (int i = 1; i < argc; ++i)
2328
{
24-
// only handle prettyfying option
29+
// handle prettyfying option
2530
if ("-p" == string(argv[i])) pretty ++;
26-
if ("--pretty" == string(argv[i])) pretty ++;
31+
else if ("--pretty" == string(argv[i])) pretty ++;
32+
// handle other bitwise options (comment related)
33+
else if ("-k" == string(argv[i])) options |= SASS2SCSS_KEEP_COMMENT;
34+
else if ("--keep" == string(argv[i])) options |= SASS2SCSS_KEEP_COMMENT;
35+
else if ("-s" == string(argv[i])) options |= SASS2SCSS_STRIP_COMMENT;
36+
else if ("--strip" == string(argv[i])) options |= SASS2SCSS_STRIP_COMMENT;
37+
else if ("-c" == string(argv[i])) options |= SASS2SCSS_CONVERT_COMMENT;
38+
else if ("--convert" == string(argv[i])) options |= SASS2SCSS_CONVERT_COMMENT;
39+
// error out with a generic error message (keep it simple for now)
40+
else { cerr << "Unknown command line option " << argv[i] << endl; exit(EXIT_FAILURE); }
2741
}
2842

2943
// declare variable
@@ -43,7 +57,11 @@ int main (int argc, char** argv)
4357
if (cin.eof()) break;
4458
};
4559

60+
// simple assertion for valid value
61+
if (pretty > SASS2SCSS_PRETTIFY_3)
62+
{ pretty = SASS2SCSS_PRETTIFY_3; }
63+
4664
// print the resulting scss
47-
cout << Sass::sass2scss (sass, pretty);
65+
cout << Sass::sass2scss (sass, pretty | options);
4866

4967
}

0 commit comments

Comments
 (0)