[enhance] create demo with function bench --site sitename make-demo` (#9212)

diff --git a/erpnext/commands/__init__.py b/erpnext/commands/__init__.py
new file mode 100644
index 0000000..6ffa6a3
--- /dev/null
+++ b/erpnext/commands/__init__.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors
+# MIT License. See license.txt
+
+from __future__ import unicode_literals, absolute_import, print_function
+import click
+import frappe
+from frappe.commands import pass_context, get_site
+
+def call_command(cmd, context):
+	return click.Context(cmd, obj=context).forward(cmd)
+
+@click.command('make-demo')
+@click.option('--site', help='site name')
+@click.option('--domain', default='Manufacturing')
+@click.option('--days', default=100,
+	help='Run the demo for so many days. Default 100')
+@click.option('--resume', default=False, is_flag=True,
+	help='Continue running the demo for given days')
+@pass_context
+def make_demo(context, site, domain='Manufacturing', days=100, resume=False):
+	"Reinstall site and setup demo"
+	from frappe.commands.site import _reinstall
+	from frappe.installer import install_app
+
+	site = get_site(context)
+
+	if resume:
+		with frappe.init_site(site):
+			frappe.connect()
+			from erpnext.demo import demo
+			demo.simulate(days=days)
+	else:
+		_reinstall(site, yes=True)
+		with frappe.init_site(site=site):
+			frappe.connect()
+			if not 'erpnext' in frappe.get_installed_apps():
+				install_app('erpnext')
+
+			# import needs site
+			from erpnext.demo import demo
+			demo.make(domain, days)
+
+commands = [
+	make_demo
+]
\ No newline at end of file
diff --git a/erpnext/demo/demo.py b/erpnext/demo/demo.py
index a270e05..9fde264 100644
--- a/erpnext/demo/demo.py
+++ b/erpnext/demo/demo.py
@@ -22,7 +22,7 @@
 
 """
 
-def make(domain='Manufacturing'):
+def make(domain='Manufacturing', days=100):
 	frappe.flags.domain = domain
 	frappe.flags.mute_emails = True
 	setup_data.setup(domain)
@@ -36,16 +36,17 @@
 	frappe.init(site)
 	frappe.connect()
 
-	simulate(domain)
+	simulate(domain, days)
 
-def simulate(domain='Manufacturing'):
-	runs_for = frappe.flags.runs_for or 150
+def simulate(domain='Manufacturing', days=100):
+	runs_for = frappe.flags.runs_for or days
 	frappe.flags.company = erpnext.get_default_company()
 	frappe.flags.mute_emails = True
 
 	if not frappe.flags.start_date:
 		# start date = 100 days back
-		frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(), -1 * runs_for)
+		frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(),
+			-1 * runs_for)
 
 	current_date = frappe.utils.getdate(frappe.flags.start_date)